/// <summary> /// Saves the industry information. /// </summary> /// <param name="industryInfo">The industry information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">industryInfo</exception> public string SaveIndustryInfo(IIndustryView industryInfo) { if (industryInfo == null) { throw new ArgumentNullException(nameof(industryInfo)); } var result = string.Empty; var newRecord = new Industry { IndustryName = industryInfo.IndustryName, IsActive = true, DateCreated = DateTime.UtcNow }; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { dbContext.Industries.Add(newRecord); dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("SaveIndustryInfo - {0}, {1}", e.Message, e.InnerException != null ? e.InnerException.InnerException.Message : ""); } return(result); }
/// <summary> /// Updates the industry information. /// </summary> /// <param name="IndustryInfo">The industry information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">IndustryInfo</exception> public string UpdateIndustryInfo(IIndustryView IndustryInfo) { if (IndustryInfo == null) { throw new ArgumentNullException(nameof(IndustryInfo)); } var result = string.Empty; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { var data = dbContext.Industries.SingleOrDefault(a => a.IndustryId.Equals(IndustryInfo.IndustryId)); data.IndustryId = IndustryInfo.IndustryId; data.IndustryName = IndustryInfo.IndustryName; data.DateCreated = IndustryInfo.DateCreated; dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("SaveIndustryInfo - {0} , {1}", e.Message, e.InnerException != null ? e.InnerException.InnerException.Message : ""); } return(result); }
/// <summary> /// Creates the updated industry view. /// </summary> /// <param name="industryInfo">The industry information.</param> /// <param name="processingMessage">The processing message.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">industryInfo</exception> public IIndustryView CreateUpdatedIndustryView(IIndustryView industryInfo, string processingMessage) { if (industryInfo == null) { throw new ArgumentNullException(nameof(industryInfo)); } industryInfo.ProcessingMessage = processingMessage; return(industryInfo); }
/// <summary> /// Processes the industry create view. /// </summary> /// <param name="industryInfo">The industry information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">industryInfo</exception> public string ProcessIndustryCreateView(IIndustryView industryInfo) { if (industryInfo == null) { throw new ArgumentNullException(nameof(industryInfo)); } var processingMessage = string.Empty; var message = this.industryRepository.SaveIndustryInfo(industryInfo); return(message); }
/// <summary> /// Processes the industry edit view. /// </summary> /// <param name="IndustryInfo">The industry information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">IndustryInfo</exception> public string ProcessIndustryEditView(IIndustryView IndustryInfo) { if (IndustryInfo == null) { throw new ArgumentNullException(nameof(IndustryInfo)); } var processingMessage = string.Empty; var isDataOkay = true; var returnViewModel = industryViewModelFactory.CreateUpdatedIndustryView(IndustryInfo, processingMessage); var message = this.industryRepository.UpdateIndustryInfo(IndustryInfo); return(message); }
/// <summary> /// Processes the industry edit view. /// </summary> /// <param name="industryInfo">The industry information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">IndustryInfo</exception> public string ProcessIndustryEditView(IIndustryView industryInfo) { if (industryInfo == null) { throw new ArgumentNullException(nameof(industryInfo)); } var message = String.Empty; // Check if the Insdustry is already Created Before to Prevent Duplicate var recordExisted = this.industryRepository.GetIndustryByName(industryInfo.IndustryName); if (recordExisted != null) { message = Messages.IndustryAlreadyExisted; } else { message = this.industryRepository.UpdateIndustryInfo(industryInfo); } return(message); }
/// <summary> /// Gets the industry create view. /// </summary> /// <param name="industryInfo">The industry information.</param> /// <param name="processingMessage">The processing message.</param> /// <returns></returns> public IIndustryView GetIndustryCreateView(IIndustryView industryInfo, string processingMessage) { var returnViewModel = industryViewModelFactory.CreateUpdatedIndustryView(industryInfo, processingMessage); return(returnViewModel); }