// GET: VacationAllocationController public ActionResult Index() { List <VacationRequest> requests = _db.VacationRequests.ToList(); foreach (var request in requests) { if (request.Status == true) { if (!_db.VacationAllocations.Any(q => q.EmployeeId == request.EmployeeId && q.VacationTypeId == request.VacationTypeId)) { VacationAllocation allocation = new VacationAllocation(); allocation.Employee = request.Employee; allocation.EmployeeId = request.EmployeeId; allocation.VacationType = request.VacationType; allocation.VacationTypeId = request.VacationTypeId; allocation.Used++; _db.VacationAllocations.Add(allocation); _db.SaveChanges(); } else { VacationAllocation allocation = _db.VacationAllocations.FirstOrDefault(q => q.EmployeeId == request.EmployeeId && q.VacationTypeId == request.VacationTypeId); allocation.Used++; _db.VacationAllocations.Update(allocation); _db.SaveChanges(); } } } List <VacationAllocationVM> alloc = Maplist(_db.VacationAllocations.ToList()); return(View(alloc)); }
public VacationAllocationVM Map(VacationAllocation allocation) { VacationAllocationVM obj = new VacationAllocationVM(); obj.Id = allocation.Id; obj.EmployeeId = allocation.EmployeeId; obj.VacationTypeId = allocation.VacationTypeId; obj.Used = allocation.Used; obj.EmployeeName = _db.Employees.Find(allocation.EmployeeId).fullname; obj.VacationTypeName = _db.VacationTypes.Find(allocation.VacationTypeId).Name; return(obj); }
public async Task <bool> Delete(VacationAllocation entity) { _db.VacationAllocations.Remove(entity); return(await Save()); }
public async Task <bool> Update(VacationAllocation entity) { _db.VacationAllocations.Update(entity); return(await Save()); }
public async Task <bool> Create(VacationAllocation entity) { await _db.VacationAllocations.AddAsync(entity); return(await Save()); }