public BusinessSegment Post(BusinessSegment businessSegment) { if (businessSegment == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(businessSegmentService.AddUpdateBusinessSegment(businessSegment.CreateFrom()).CreateFromm()); }
/// <summary> /// Method to Add Business Segment properties /// </summary> private void SetNewBusinessSegmentProPerties(BusinessSegment businessSegment) { businessSegment.RecCreatedBy = businessSegment.RecLastUpdatedBy = businessSegmentRepository.LoggedInUserIdentity; businessSegment.RecCreatedDt = businessSegment.RecLastUpdatedDt = DateTime.Now; businessSegment.RowVersion = 0; businessSegment.UserDomainKey = businessSegmentRepository.UserDomainKey; }
/// <summary> /// Create web model from entity /// </summary> public static ApiModel.BusinessSegmentDropDown CreateFrom(this BusinessSegment source) { return(new ApiModel.BusinessSegmentDropDown { BusinessSegmentId = source.BusinessSegmentId, BusinessSegmentCodeName = source.BusinessSegmentCode + " - " + source.BusinessSegmentName }); }
/// <summary> /// Method to update Business Segment properties /// </summary> private void UpdateBusinessSegmentProPerties(BusinessSegment businessSegment, BusinessSegment dbVersion) { dbVersion.RecLastUpdatedBy = businessSegmentRepository.LoggedInUserIdentity; dbVersion.RecLastUpdatedDt = DateTime.Now; dbVersion.RowVersion = dbVersion.RowVersion + 1; dbVersion.BusinessSegmentCode = businessSegment.BusinessSegmentCode; dbVersion.BusinessSegmentName = businessSegment.BusinessSegmentName; dbVersion.BusinessSegmentDescription = businessSegment.BusinessSegmentDescription; }
public bool Delete(BusinessSegment businessSegment) { if (businessSegment == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } businessSegmentService.DeleteBusinessSegment(businessSegment.BusinessSegmentId); return(true); }
/// <summary> /// Create from domain model /// </summary> public static ApiModel.BusinessSegment CreateFromm(this BusinessSegment source) { return(new ApiModel.BusinessSegment { BusinessSegmentId = source.BusinessSegmentId, BusinessSegmentCode = source.BusinessSegmentCode, BusinessSegmentName = source.BusinessSegmentName, BusinessSegmentDescription = source.BusinessSegmentDescription, }); }
/// <summary> /// Delete BusinessSegment by BusinessSegmentId /// </summary> public void DeleteBusinessSegment(long businessSegmentId) { BusinessSegment dbversion = businessSegmentRepository.Find(businessSegmentId); ValidateAssociation(businessSegmentId); if (dbversion == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Business Segment with Id {0} not found!", businessSegmentId)); } businessSegmentRepository.Delete(dbversion); businessSegmentRepository.SaveChanges(); }
/// <summary> /// Add or Update Business Segment object /// </summary> public BusinessSegment AddUpdateBusinessSegment(BusinessSegment businessSegment) { BusinessSegment dbVersion = businessSegmentRepository.Find(businessSegment.BusinessSegmentId); //Code Duplication Check if (businessSegmentRepository.IsBusinessSegmentCodeExists(businessSegment)) { throw new CaresException(Resources.Organization.BusinessSegment.BusinessSegmentCodeExistsError); } if (dbVersion != null) { UpdateBusinessSegmentProPerties(businessSegment, dbVersion); businessSegmentRepository.Update(dbVersion); } else { SetNewBusinessSegmentProPerties(businessSegment); businessSegmentRepository.Add(businessSegment); } businessSegmentRepository.SaveChanges(); // To Load the proprties return(businessSegmentRepository.Find(businessSegment.BusinessSegmentId)); }