public ActionResult Edit(SubCategoryModel subCategory) { try { ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList(); // || (!ModelState.IsValid && ModelState.Values.Count(p => p.Errors.Count > 0) == 1) if (ModelState.IsValid) { if (subCategoryService.Exists(subCategory.SubCategoryName, subCategory.SubCategoryID)) { DisplayWarningMessage($"Sub-Category Name '{subCategory.SubCategoryName}' is duplicate"); return(View(subCategory)); } DropDownSubCategoryDto subCategoryDto = Mapper.Map <SubCategoryModel, DropDownSubCategoryDto>(subCategory); subCategoryService.UpdateSubCategory(subCategoryDto); DisplaySuccessMessage("Sub-Category has been updated successfully"); Session["SelectedCategoryID"] = subCategory.CategoryID.ToString(); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayUpdateErrorMessage(exp); } return(View(subCategory)); }
public ActionResult Create(SubCategoryModel subCategory) { try { ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList(); if (ModelState.IsValid) { if (subCategoryService.Exists(subCategory.SubCategoryName)) { DisplayWarningMessage($"Sub-Category Name '{subCategory.SubCategoryName}' is duplicate"); return(View(subCategory)); } DropDownSubCategoryDto subCategoryModel = Mapper.Map <SubCategoryModel, DropDownSubCategoryDto>(subCategory); subCategoryService.CreateSubCategory(subCategoryModel); DisplaySuccessMessage($"New Sub-Category '{subCategory.SubCategoryName}' has been stored successfully"); Session["SelectedCategoryID"] = subCategory.CategoryID.ToString(); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayUpdateErrorMessage(exp); } return(View(subCategory)); }
// GET: SubCategory/Edit/5 public ActionResult Edit(int?id) { SubCategoryModel uiCategory = new SubCategoryModel(); if (!id.HasValue) { DisplayWarningMessage("Looks like, the ID is missing in your request"); return(RedirectToAction("List")); } try { if (!subCategoryService.Exists(id.Value)) { DisplayWarningMessage($"Sorry, We couldn't find the Sub-Category with ID: {id.Value}"); return(RedirectToAction("List")); } ViewBag.CategoryListItems = (IEnumerable <SelectListItem>)Session["CategoryListItems"] ?? GetCategoriesDropDownList(); DropDownSubCategoryDto category = subCategoryService.GetSubCategory(id.Value); uiCategory = Mapper.Map <DropDownSubCategoryDto, SubCategoryModel>(category); } catch (Exception exp) { DisplayReadErrorMessage(exp); } return(View(uiCategory)); }
public void Add(DropDownSubCategoryDto entity) { DropDownSubCategory subCategory = CreateBusinessEntity(entity, true); Entities.Add(subCategory); DataContext.Entry(subCategory).State = EntityState.Added; DataContext.SaveChanges(); }
private void MigrateEntity(DropDownSubCategoryDto sourceEntity, DropDownSubCategory targetEntity) { targetEntity.CategoryID = sourceEntity.CategoryID; targetEntity.Description = sourceEntity.Description; targetEntity.ShortName = sourceEntity.ShortName; targetEntity.SubCategoryID = sourceEntity.SubCategoryID; targetEntity.SubCategoryName = sourceEntity.SubCategoryName; targetEntity.UpdateTimeStamp(sourceEntity.LoggedInUserName); }
public void Delete(DropDownSubCategoryDto entity) { DropDownSubCategory subCategory = Entities.FirstOrDefault(e => e.SubCategoryID == entity.SubCategoryID); subCategory.IsDeleted = true; subCategory.UpdateTimeStamp(entity.LoggedInUserName); Entities.Add(subCategory); DataContext.Entry(subCategory).State = EntityState.Modified; DataContext.SaveChanges(); }
public void Update(DropDownSubCategoryDto entity) { DropDownSubCategory buzEntity = Entities.FirstOrDefault(e => e.SubCategoryID == entity.SubCategoryID); MigrateEntity(entity, buzEntity); buzEntity.UpdateTimeStamp(entity.LoggedInUserName); Entities.Add(buzEntity); DataContext.Entry(buzEntity).State = EntityState.Modified; DataContext.SaveChanges(); }
private DropDownSubCategory CreateBusinessEntity(DropDownSubCategoryDto subCategoryDto, bool isNewEntity = false) { DropDownSubCategory category = new DropDownSubCategory { CategoryID = subCategoryDto.CategoryID, SubCategoryID = subCategoryDto.SubCategoryID, SubCategoryName = subCategoryDto.SubCategoryName, Description = subCategoryDto.Description, ShortName = subCategoryDto.ShortName, }; category.UpdateTimeStamp(subCategoryDto.LoggedInUserName, true); return(category); }
private void UploadButton_Click(object sender, EventArgs e) { if (empDataTable == null || (empDataTable != null && empDataTable.Rows.Count == 0)) { MessageBox.Show("No data to upload"); return; } try { EmployeeRepository repository = new EmployeeRepository(); DropDownSubCategoryRepository subCategoryRepository = new DropDownSubCategoryRepository(); PracticeRepository practiceRepo = new PracticeRepository(); SubPracticeRepository subPracticeRepo = new SubPracticeRepository(); foreach (DataRow row in empDataTable.Rows) { try { if (repository.IsDuplicateEmployeeID(row["EmpID"].ToString().Trim())) { row["UploadStatus"] = "Failed"; row["StatusMessage"] = "Duplicate Employee ID"; continue; } if (repository.IsDuplicateName(row["FirstName"].ToString().Trim(), row["LastName"].ToString().Trim())) { row["UploadStatus"] = "Failed"; row["StatusMessage"] = "Duplicate Employee Name"; continue; } DropDownSubCategoryDto buType = subCategoryRepository.GetByName(row["BU"].ToString(), (int)CategoryType.BusinessUnit); string empID = row["EmpID"].ToString(); string empType = "Permanent"; if (empID.StartsWith("CE")) { empType = "Contractor"; } else if (empID.StartsWith("CI")) { empType = "Internship"; } else if (empID.StartsWith("YTJ")) { empType = "Yet to Join"; } DropDownSubCategoryDto employmentType = subCategoryRepository.GetByName(empType, (int)CategoryType.EmploymentType); PracticeDto practiceDto = practiceRepo.GetByNameOrDefault(row["POD"].ToString()); SubPracticeDto subPracticeDto = subPracticeRepo.GetByName(row["Competency"].ToString(), practiceDto.PracticeID); EmployeeDto entry = new EmployeeDto { BusinessUnitID = buType.SubCategoryID, DateOfJoin = DateTime.Parse(row["DoJ"].ToString()), EmployeeID = empID, EmploymentTypeID = employmentType.SubCategoryID, FirstName = row["FirstName"].ToString(), LastName = row["LastName"].ToString(), PracticeID = practiceDto.PracticeID, PrimarySkills = row["PrimarySkills"].ToString(), SecondarySkills = row["SecondarySkills"].ToString(), SubPracticeID = subPracticeDto.SubPracticeID, }; if (string.IsNullOrWhiteSpace(row["LWD"].ToString()) == false) { entry.LastWorkingDay = DateTime.Parse(row["LWD"].ToString()); } repository.Add(entry); row["UploadStatus"] = "Successfully Uploaded"; row["StatusMessage"] = ""; } catch (Exception exp) { row["UploadStatus"] = "Failed"; row["StatusMessage"] = exp.Message; } } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
public void DeleteSubCategory(DropDownSubCategoryDto category) { repository.Delete(category); }
public void UpdateSubCategory(DropDownSubCategoryDto category) { repository.Update(category); }
public void CreateSubCategory(DropDownSubCategoryDto subCategory) { repository.Add(subCategory); }