Skip to content

Commit

Permalink
Merge branch 'development' into issue_52-pantalla-perfil
Browse files Browse the repository at this point in the history
  • Loading branch information
eatskolnikov authored Sep 3, 2019
2 parents 08af59a + ceeb9ba commit 15f1490
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 220 deletions.
75 changes: 69 additions & 6 deletions AppServices/Services/JobsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Domain;

namespace AppServices.Services
Expand All @@ -16,7 +17,7 @@ public override List<Job> GetAll()
Title = "Trabajo de prueba",
Description="Esto es un lorem ipsum",
HowToApply="Para aplicar mandame un correo plz",

Approved=true,
Company= new Company
{
Url="https://megsoftconsulting.com/",
Expand All @@ -29,7 +30,7 @@ public override List<Job> GetAll()
Title = "Trabajo de prueba 2",
Description="Esto es un lorem ipsum",
HowToApply="Para aplicar mandame un correo plz",

Approved=true,
Company= new Company
{
Url="https://megsoftconsulting.com/",
Expand All @@ -55,12 +56,14 @@ public override List<Job> GetAll()
Title = "Trabajo de prueba 55",
Description="Esto es un lorem ipsum",
HowToApply="Para aplicar mandame un correo plz",

UserId=10,
Approved = false,
Company= new Company
{
Url="https://megsoftconsulting.com/",
LogoUrl = "https://localhost:5001/img/logo.png"
}
},

},
new Job
{
Expand All @@ -77,8 +80,7 @@ public override List<Job> GetAll()
},
};
}

public List<Job> GetByUserProfile(int id)
public List<Job> GetByUserProfile(int id)
{
return new List<Job>
{
Expand Down Expand Up @@ -123,10 +125,71 @@ public List<Job> GetByUserProfile(int id)
},
};
}

public Job GetDetails(int id, bool isPreview = false)
{
var jobList = this.GetAll();
var job = jobList
.Where(j => j.Id == id && j.Approved == !isPreview)
.FirstOrDefault();

return job;
}

public IEnumerable<Job> GetRecentJobs()
{
List<Job> jobsList = new List<Job>
{
new Job
{
Id=1,
Title = "No hay trabajo",
Description="Esta no es una descripción para un trabajo",
HowToApply="No apliquen por favor",
Company= new Company
{
Url="https://megsoftconsulting.com/",
LogoUrl = "https://localhost:5001/img/logo.png"
}
},
new Job
{
Id=2,
Title = "Trabajo de prueba 2",
Description="Esto es un lorem ipsum",
HowToApply="Para aplicar mandame un correo plz",
Title = "No entienden que no hay trabajo?",
Description="Esto es un lorem ipsum",
HowToApply="Ni lo intenten",
Company= new Company
{
Url="https://megsoftconsulting.com/",
LogoUrl = "https://localhost:5001/img/logo.png"
}
},
new Job
{
Id=14,
Title = "Trabajo de prueba 4",
Description="Esto es un lorem ipsum",
HowToApply="Para aplicar mandame un correo plz",

Company= new Company
{
Url="https://megsoftconsulting.com/",
LogoUrl = "https://localhost:5001/img/logo.png"
}
},
};
var recentJobs = jobsList.OrderByDescending(x => x.CreatedAt).Take(10);
return recentJobs;
}
}

public interface IJobsService : IBaseService<Job>
{
List<Job> GetByUserProfile(int id);
IEnumerable<Job> GetRecentJobs();
Job GetDetails(int id, bool isPreview = false);
}
}
19 changes: 17 additions & 2 deletions Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using AppServices.Services;
using Microsoft.AspNetCore.Mvc;
using Web.Models;

using Web.ViewModels;

namespace Web.Controllers
{
public class HomeController : Controller
{
private IJobsService _jobsService;

public HomeController()
{
_jobsService = new JobsService();
}

public IActionResult Index()
{
return View();
var recentJobs = _jobsService.GetRecentJobs();
var viewModel = new HomeViewModel
{
Jobs = recentJobs
};

return View(viewModel);
}

public IActionResult Privacy()
Expand Down
93 changes: 67 additions & 26 deletions Web/Controllers/JobsController.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
using System;
using Microsoft.AspNetCore.Mvc;
using AppServices;
using AppServices.Services;
using Web.ViewModels;

namespace Web.Controllers
{
public class JobsController : Controller
using System;
using Microsoft.AspNetCore.Mvc;
using AppServices;
using AppServices.Services;
using Web.ViewModels;
using Domain;

namespace Web.Controllers
{
public class JobsController : Controller
{
private IJobsService _jobsService;

public JobsController()
{
_jobsService = new JobsService();
public JobsController()
{
_jobsService = new JobsService();
}

public IActionResult Index(string keyword = "", bool isRemote = false)
{
var filteredJobs = _jobsService.GetAll();
var viewModel = new JobsViewModel
{
Keyword = keyword,
IsRemote = isRemote,
Jobs = filteredJobs
var filteredJobs = _jobsService.GetAll();
var viewModel = new JobsViewModel
{
Keyword = keyword,
IsRemote = isRemote,
Jobs = filteredJobs
};
return View(viewModel);
}


public IActionResult Details()
}


public IActionResult Details(string Id, bool isPreview)
{
return View();
}
}
}

if (String.IsNullOrEmpty(Id))
return RedirectToAction(nameof(this.Index));


int jobId = this.GetJobIdFromTitle(Id);

if (jobId == 0)
return RedirectToAction(nameof(this.Index));

var job = this._jobsService.GetDetails(jobId, isPreview);

//Manage error message
if (job == null)
return RedirectToAction(nameof(this.Index));

//If reach this line is because the job exists
var viewModel = new JobsViewModel
{
Job = job
};

if (isPreview)
{
viewModel.IsPreview = isPreview;
return View(viewModel);
}



return View(viewModel);
}


private int GetJobIdFromTitle(string title)
{
var url = title.Split('-');
if (String.IsNullOrEmpty(title) || title.Length == 0 || !int.TryParse(url[0], out int id))
return 0;
return id;
}

}
}
9 changes: 5 additions & 4 deletions Web/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using Domain;

namespace Web.ViewModels
{
public class HomeViewModel
public class HomeViewModel : BaseViewModel
{
public HomeViewModel()
{
}
public IEnumerable<Job> Jobs { get; set; }
}
}
4 changes: 4 additions & 0 deletions Web/ViewModels/JobsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public class JobsViewModel : BaseViewModel
public bool IsRemote { get; set; }

public List<Job> Jobs { get; set; }

public Job Job { get; set; }

public bool IsPreview { get; set; }
}
}
Loading

0 comments on commit 15f1490

Please sign in to comment.