// GET: ModelMasterController/Edit/5 public async Task <ActionResult> Edit(int id) { var modelInfo = _modelMasterService.GetModelbyIdAsync(id); if (modelInfo == null) { return(RedirectToAction("List")); } var viewModel = new ModelsListModel { Id = modelInfo.Id, ModelCode = modelInfo.ModelCode, ModelName = modelInfo.ModelName, FriendlyName = modelInfo.FriendlyName, SelectedVarientIds = (await _modelMasterService.GetModelVarientMappingByModelId(modelInfo.Id)).Select(x => x.VarientId).ToArray(), Active = modelInfo.Active, ContinueEditing = IsContinueEditingAllowed() }; var varientsList = await _varientMasterService.GetAllVarientsListAsync(); foreach (var item in varientsList) { viewModel.AvaillabelVarientsList.Add(new SelectListItem { Value = item.Id.ToString(), Text = item.VerientName }); } return(View(viewModel)); }
public async Task <ActionResult> Edit(ModelsListModel model, bool continueEditing) { try { var modelInfo = _modelMasterService.GetModelbyIdAsync(model.Id); if (modelInfo == null) { return(RedirectToAction("List")); } modelInfo.ModelCode = model.ModelCode; modelInfo.ModelName = model.ModelName; modelInfo.FriendlyName = model.FriendlyName; modelInfo.Active = model.Active; modelInfo.DateUpdated = DateTime.UtcNow; modelInfo.ByUser = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value); await _modelMasterService.UpdateAsync(modelInfo); if (model.SelectedVarientIds.Length > 0) { //delete old mapping await _modelMasterService.RemoveVarientMappingByModelAsync(await _modelMasterService.GetModelVarientMappingByModelId(modelInfo.Id)); foreach (var varMap in model.SelectedVarientIds) { await _modelMasterService.AddVarientMappingAsync(new ModelVarientMapping { ModelId = modelInfo.Id, VarientId = varMap }); } } AllowContinueEditing(continueEditing); TempData["UserMessageSuccess"] = "Record saved sucessfully."; if (continueEditing) { return(RedirectToAction(nameof(Edit), new { id = modelInfo.Id })); } return(RedirectToAction(nameof(List))); } catch (Exception ex) { TempData["UserMessageError"] = ex.Message.ToString(); return(RedirectToAction(nameof(Create))); } }
// GET: ModelMasterController/Create public async Task <ActionResult> Create() { var model = new ModelsListModel(); var varientsList = await _varientMasterService.GetAllVarientsListAsync(); foreach (var item in varientsList) { model.AvaillabelVarientsList.Add(new SelectListItem { Value = item.Id.ToString(), Text = item.VarientCode }); } return(View(new ModelsListModel())); }
public async Task <ActionResult> Create(ModelsListModel model, bool continueEditing) { try { var modelInfo = new ModelMaster { ModelCode = model.ModelCode, ModelName = model.ModelName, FriendlyName = model.FriendlyName, Active = model.Active, Deleted = false, DateUpdated = DateTime.UtcNow, DateCreated = DateTime.UtcNow, ByUser = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value) }; await _modelMasterService.InsertAsync(modelInfo); //add model varient mapping foreach (var varMap in model.SelectedVarientIds) { await _modelMasterService.AddVarientMappingAsync(new ModelVarientMapping { ModelId = modelInfo.Id, VarientId = varMap }); } if (continueEditing) { return(RedirectToAction(nameof(Edit), new { id = modelInfo.Id })); } TempData["UserMessageSuccess"] = "Record saved sucessfully."; return(RedirectToAction(nameof(List))); } catch (Exception ex) { TempData["UserMessageError"] = ex.Message.ToString(); return(RedirectToAction(nameof(Create))); } }