Ejemplo n.º 1
0
 public BusinessSegment Post(BusinessSegment businessSegment)
 {
     if (businessSegment == null || !ModelState.IsValid)
     {
         throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request");
     }
     return(businessSegmentService.AddUpdateBusinessSegment(businessSegment.CreateFrom()).CreateFromm());
 }
Ejemplo n.º 2
0
 /// <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;
 }
Ejemplo n.º 3
0
 /// <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
     });
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
 public bool Delete(BusinessSegment businessSegment)
 {
     if (businessSegment == null || !ModelState.IsValid)
     {
         throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request");
     }
     businessSegmentService.DeleteBusinessSegment(businessSegment.BusinessSegmentId);
     return(true);
 }
Ejemplo n.º 6
0
 /// <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,
     });
 }
Ejemplo n.º 7
0
        /// <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();
        }
Ejemplo n.º 8
0
        /// <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));
        }