public async Task <IActionResult> Edit(int id, ClientRequestViewModel activityDetails) { if (id != activityDetails.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(activityDetails.GetModel()); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActivityDetailsExists(activityDetails.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } activityDetails.loadLists(_context); return(View(activityDetails)); }
public async Task <IActionResult> Create(ClientRequestViewModel activityDetails) { var clientId = repository.GetCurrentAgentId(User.Identity.Name); //Generate number Random rd = new Random(); Int32 batchCode = rd.Next(9999); activityDetails.BatchNo = "B-" + batchCode.ToString(); if (ModelState.IsValid) { ClientRequest request = new ClientRequest(); { request.Id = activityDetails.Id; request.BatchNo = activityDetails.BatchNo; request.ClientId = clientId; request.OutletId = activityDetails.OutletId; request.StartDate = activityDetails.StartDate; request.EndDate = activityDetails.EndDate; request.Days = activityDetails.Days; request.Age = activityDetails.Age; request.NbAgentShift1 = activityDetails.NbAgentShift1; request.NbAgentShift2 = activityDetails.NbAgentShift2; request.NbAgentShift3 = activityDetails.NbAgentShift3; request.NbAgentShift4 = activityDetails.NbAgentShift4; request.MechanismId = activityDetails.MechanismId; request.GenderId = activityDetails.GenderId; request.LanguageId = activityDetails.LanguageId; request.GradeId = activityDetails.GradeId; request.SkillId = activityDetails.SkillId; } if (request.GenderId == 0) { request.GenderId = null; } if (request.LanguageId == 0) { request.LanguageId = null; } if (request.GradeId == 0) { request.GradeId = null; } if (request.SkillId == 0) { request.SkillId = null; } _context.Add(request); await _context.SaveChangesAsync(); ClientRequestDetailsViewModel details = new ClientRequestDetailsViewModel(); int id = request.Id; details.ClientRequestId = request.Id; Util util = new Util(); foreach (DateTime day in util.EachDay(activityDetails.StartDate, activityDetails.EndDate)) { var a = (int)day.DayOfWeek; foreach (char d in activityDetails.Days) { var val = (int)Char.GetNumericValue(d); if (a == val) { details.Date = day; _context.Add(details.GetModel()); await _context.SaveChangesAsync(); } } } return(RedirectToAction(nameof(ClientRequest))); } activityDetails.loadLists(_context); return(View(activityDetails)); }