示例#1
0
 /// <summary>
 /// Delete a AdditionalCharge
 /// </summary>
 public void Delete(AdditionalChargeType additionalChargeType)
 {
     if (additionalChargeType == null || !ModelState.IsValid)
     {
         throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request");
     }
     additionalChargeService.DeleteAdditionalCharge(additionalChargeService.FindById(additionalChargeType.AdditionalChargeTypeId));
 }
示例#2
0
        /// <summary>
        ///  Additional Driver Charge Detail
        /// </summary>
        /// <returns></returns>
        public List <Models.AdditionalCharge> Get([FromUri] AdditionalChargeType additionalChargeType)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request");
            }
            List <AdditionalCharge> result =
                additionalChargeService.GetAdditionalChargesByAdditionChargeTypeId(additionalChargeType.AdditionalChargeTypeId).ToList();

            return(result.Count > 0 ? result.Select(x => x.CreateFrom()).ToList() : null);
        }
示例#3
0
        /// <summary>
        /// Save Additional Charge
        /// </summary>
        /// <param name="additionalChargeType"></param>
        /// <returns></returns>
        public AdditionalChargeType SaveAdditionalCharge(AdditionalChargeType additionalChargeType)
        {
            AdditionalChargeType additionalChargeTypeDbVersion =
                additionalChargeTypeRepository.Find(additionalChargeType.AdditionalChargeTypeId);

            if (additionalChargeTypeDbVersion == null) //Add Case
            {
                AditionalChargeValidation(additionalChargeType.AdditionalCharges);

                additionalChargeType.IsActive            = true;
                additionalChargeType.IsDeleted           =
                    additionalChargeType.IsPrivate       = additionalChargeType.IsReadOnly = false;
                additionalChargeType.RecLastUpdatedBy    =
                    additionalChargeType.RecCreatedBy    = additionalChargeTypeRepository.LoggedInUserIdentity;
                additionalChargeType.RecCreatedDt        = additionalChargeType.RecLastUpdatedDt = DateTime.Now;
                additionalChargeType.RowVersion          = 0;
                additionalChargeType.AdditionalChargeKey = 0;
                additionalChargeType.UserDomainKey       = additionalChargeTypeRepository.UserDomainKey;

                if (additionalChargeType.AdditionalCharges != null)
                {
                    foreach (var item in additionalChargeType.AdditionalCharges)
                    {
                        item.IsActive         = true;
                        item.IsDeleted        = item.IsPrivate = item.IsReadOnly = false;
                        item.RecLastUpdatedBy = item.RecCreatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                        item.RecCreatedDt     = item.RecLastUpdatedDt = DateTime.Now;
                        item.RowVersion       = 0;
                        item.RevisionNumber   = 0;
                        item.UserDomainKey    = additionalChargeTypeRepository.UserDomainKey;
                    }
                }
                additionalChargeTypeRepository.Add(additionalChargeType);
                additionalChargeTypeRepository.SaveChanges();
            }
            else //Update Case
            {
                additionalChargeTypeDbVersion.RecLastUpdatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                additionalChargeTypeDbVersion.RecLastUpdatedDt = DateTime.Now;
                additionalChargeTypeDbVersion.IsEditable       = additionalChargeType.IsEditable;

                foreach (var item in additionalChargeType.AdditionalCharges)
                {
                    if (
                        additionalChargeTypeDbVersion.AdditionalCharges.All(
                            x =>
                            x.AdditionalChargeId != item.AdditionalChargeId ||
                            item.AdditionalChargeId == 0))
                    {
                        item.IsActive         = true;
                        item.IsDeleted        = item.IsPrivate = item.IsReadOnly = false;
                        item.RecLastUpdatedBy = item.RecCreatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                        item.RecCreatedDt     = item.RecLastUpdatedDt = DateTime.Now;
                        item.RowVersion       = 0;
                        item.RevisionNumber   = 0;
                        item.UserDomainKey    = additionalChargeTypeRepository.UserDomainKey;
                        additionalChargeTypeDbVersion.AdditionalCharges.Add(item);
                    }
                    else
                    {
                        if (additionalChargeTypeDbVersion.AdditionalCharges.Any(
                                x =>
                                x.AdditionalChargeId == item.AdditionalChargeId))
                        {
                            AdditionalCharge additionalChargeDbVesion =
                                additionalChargeTypeDbVersion.AdditionalCharges.First(
                                    x => x.AdditionalChargeId == item.AdditionalChargeId);
                            if (additionalChargeDbVesion.HireGroupDetailId != item.HireGroupDetailId ||
                                additionalChargeDbVesion.StartDt != item.StartDt ||
                                additionalChargeDbVesion.AdditionalChargeRate != item.AdditionalChargeRate)
                            {
                                item.IsActive               = true;
                                item.IsDeleted              = item.IsPrivate = item.IsReadOnly = false;
                                item.RecLastUpdatedBy       =
                                    item.RecCreatedBy       = additionalChargeTypeRepository.LoggedInUserIdentity;
                                item.RecCreatedDt           = item.RecLastUpdatedDt = DateTime.Now;
                                item.RowVersion             = 0;
                                item.AdditionalChargeTypeId = additionalChargeType.AdditionalChargeTypeId;
                                item.RevisionNumber         = additionalChargeDbVesion.RevisionNumber + 1;
                                item.AdditionalChargeId     = 0;
                                item.UserDomainKey          = additionalChargeTypeRepository.UserDomainKey;
                                additionalChargeRepository.Add(item);
                                additionalChargeRepository.SaveChanges();
                                additionalChargeDbVesion.ChildAdditionalChargeId = item.AdditionalChargeId;
                            }
                        }
                    }
                }
            }



            additionalChargeTypeRepository.SaveChanges();

            return(new AdditionalChargeType
            {
                AdditionalChargeTypeId = additionalChargeType.AdditionalChargeTypeId,
                AdditionalChargeTypeCode = additionalChargeType.AdditionalChargeTypeCode,
                AdditionalChargeTypeName = additionalChargeType.AdditionalChargeTypeName,
                AdditionalChargeTypeDescription = additionalChargeType.AdditionalChargeTypeDescription,
                IsEditable = additionalChargeType.IsEditable,
            });
        }
示例#4
0
 /// <summary>
 /// Delete Additional Charge
 /// </summary>
 /// <param name="additionalChargeType"></param>
 public void DeleteAdditionalCharge(AdditionalChargeType additionalChargeType)
 {
     additionalChargeTypeRepository.Delete(additionalChargeType);
     additionalChargeTypeRepository.SaveChanges();
 }