Exemplo n.º 1
0
        public VLCMilkCollectionDTO GetVLCMilkCollectionById(int vlcMilkCollectionId)
        {
            VLCMilkCollectionDTO vlcMilkCollectionDto = null;
            var vlcMilkCollection = unitOfWork.VLCMilkCollectionRepository.GetById(vlcMilkCollectionId);

            if (vlcMilkCollection != null)
            {
                vlcMilkCollectionDto = VLCMilkCollectionConvertor.ConvertToVLCMilkCollectionDto(vlcMilkCollection);
            }
            return(vlcMilkCollectionDto);
        }
Exemplo n.º 2
0
        //Post api/Customer

        public IHttpActionResult Post([FromBody] VLCMilkCollectionDTO vLCMilkCollectionDTO)
        {
            try
            {
                if (vLCMilkCollectionDTO == null)
                {
                    Ok(ResponseHelper.CreateResponseDTOForException("Argument Null"));
                }
                //Create New Customer
                ResponseDTO responseDTO = _vlcMilkCollectionService.AddVLCMilkCollection(vLCMilkCollectionDTO);

                return(Ok(responseDTO));
            }
            catch (PlatformModuleException ex)
            {
                //Write Log Here
                return(Ok(ResponseHelper.CreateResponseDTOForException(ex.Message)));
            }
        }
Exemplo n.º 3
0
        public ResponseDTO AddVLCMilkCollection(VLCMilkCollectionDTO vLCMilkCollectionDTO)
        {
            ResponseDTO responseDTO = new ResponseDTO();
            //  this.CheckForExisitngCustomer(vlcDto.MobileNumber);
            VLCMilkCollection vLCMilkCollection = new VLCMilkCollection();

            vLCMilkCollection.VLCMilkCollectionId = unitOfWork.DashboardRepository.NextNumberGenerator("VLCMilkCollection");
            vLCMilkCollection.CollectionDateTime  = DateTimeHelper.GetISTDateTime();
            vLCMilkCollection.CreatedDate         = DateTimeHelper.GetISTDateTime();
            vLCMilkCollection.ModifiedDate        = DateTimeHelper.GetISTDateTime();
            vLCMilkCollection.CreatedBy           = vLCMilkCollectionDTO.ModifiedBy = "Admin";
            vLCMilkCollection.IsDeleted           = false;
            VLCMilkCollectionConvertor.ConvertToVLCMilkCollectionEntity(ref vLCMilkCollection, vLCMilkCollectionDTO, false);
            if (vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList != null)
            {
                foreach (var vlcCollectionDtlDTO in vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList)
                {
                    this.CheckForExistingCollectionDetailByDateShiftProduct(vLCMilkCollection.CollectionDateTime.Value.Date, vLCMilkCollectionDTO.ShiftId, vlcCollectionDtlDTO.ProductId, vLCMilkCollectionDTO.CustomerId);
                    VLCMilkCollectionDtl vLCMilkCollectionDtl = new VLCMilkCollectionDtl();
                    vLCMilkCollectionDtl.VLCMilkCollectionDtlId = unitOfWork.DashboardRepository.NextNumberGenerator("VLCMilkCollectionDtl");
                    vLCMilkCollectionDtl.VLCMilkCollectionId    = vLCMilkCollection.VLCMilkCollectionId;
                    VLCMilkCollectionConvertor.ConvertToVLCMilkCollectionDtlEntity(ref vLCMilkCollectionDtl, vlcCollectionDtlDTO, false);
                    unitOfWork.VLCMilkCollectionDtlRepository.Add(vLCMilkCollectionDtl);
                }

                vLCMilkCollection.TotalAmount   = vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList.Sum(s => s.Amount);
                vLCMilkCollection.TotalQuantity = vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList.Sum(s => s.Quantity);
            }
            else
            {
                throw new PlatformModuleException("Milk Collection Detail Not Found");
            }
            unitOfWork.VLCMilkCollectionRepository.Add(vLCMilkCollection);

            unitOfWork.SaveChanges();
            responseDTO.Status  = true;
            responseDTO.Message = String.Format("Milk Collection Detail Added Successfully ");
            responseDTO.Data    = this.GetVLCCustomerCollectionByDateAndShift(vLCMilkCollectionDTO.VLCId, DateTimeHelper.GetISTDateTime().Date, vLCMilkCollectionDTO.ShiftId, 1);

            return(responseDTO);
        }
Exemplo n.º 4
0
        public static VLCMilkCollectionDTO ConvertToVLCMilkCollectionDto(VLCMilkCollection vlcMilkCollection)
        {
            VLCMilkCollectionDTO vlcMilkCollectionDTO = new VLCMilkCollectionDTO();

            vlcMilkCollectionDTO.VLCMilkCollectionId = vlcMilkCollection.VLCMilkCollectionId;
            vlcMilkCollectionDTO.VLCId         = vlcMilkCollection.VLCId.GetValueOrDefault();
            vlcMilkCollectionDTO.TotalAmount   = vlcMilkCollection.TotalAmount.GetValueOrDefault();
            vlcMilkCollectionDTO.TotalQuantity = vlcMilkCollection.TotalQuantity.GetValueOrDefault();

            ShiftEnum shift;

            Enum.TryParse <ShiftEnum>(vlcMilkCollection.ShiftId.ToString(), out shift);
            vlcMilkCollectionDTO.ShiftId = shift;

            vlcMilkCollectionDTO.CollectionDateTime = vlcMilkCollection.CollectionDateTime.HasValue ? vlcMilkCollection.CollectionDateTime.Value : DateTime.Now;

            vlcMilkCollectionDTO.CreatedBy    = vlcMilkCollection.CreatedBy;
            vlcMilkCollectionDTO.CreatedDate  = vlcMilkCollection.CreatedDate;
            vlcMilkCollectionDTO.CreatedBy    = vlcMilkCollection.CreatedBy;
            vlcMilkCollectionDTO.CreatedDate  = vlcMilkCollection.CreatedDate;
            vlcMilkCollectionDTO.IsDeleted    = vlcMilkCollection.IsDeleted.GetValueOrDefault();
            vlcMilkCollectionDTO.ModifiedBy   = vlcMilkCollection.ModifiedBy;
            vlcMilkCollectionDTO.ModifiedDate = vlcMilkCollection.ModifiedDate.GetValueOrDefault();
            vlcMilkCollectionDTO.CustomerName = vlcMilkCollection.Customer.CustomerName.ToString();
            vlcMilkCollectionDTO.VLCName      = vlcMilkCollection.VLC.VLCName.ToString();

            if (vlcMilkCollection.VLCMilkCollectionDtls != null && vlcMilkCollection.VLCMilkCollectionDtls.Count() > 0)
            {
                vlcMilkCollectionDTO.vLCMilkCollectionDtlDTOList = new List <VLCMilkCollectionDtlDTO>();
                foreach (VLCMilkCollectionDtl item in vlcMilkCollection.VLCMilkCollectionDtls)
                {
                    vlcMilkCollectionDTO.vLCMilkCollectionDtlDTOList.Add(ConvertToVLCMilkCollectionDetailDTO(item));
                }
            }

            return(vlcMilkCollectionDTO);
        }
Exemplo n.º 5
0
 public static void ConvertToVLCMilkCollectionEntity(ref VLCMilkCollection vlcMilkCollection, VLCMilkCollectionDTO vlcMilkCollectionDTO, bool isUpdate)
 {
     if (isUpdate)
     {
         vlcMilkCollection.VLCMilkCollectionId = vlcMilkCollectionDTO.VLCMilkCollectionId;
     }
     vlcMilkCollection.VLCId      = vlcMilkCollectionDTO.VLCId;
     vlcMilkCollection.CustomerId = vlcMilkCollectionDTO.CustomerId;
     vlcMilkCollection.ShiftId    = (int)vlcMilkCollectionDTO.ShiftId;
 }
Exemplo n.º 6
0
        public ResponseDTO UpdateVLCMilkCollection(VLCMilkCollectionDTO vLCMilkCollectionDTO)
        {
            ResponseDTO responseDTO = new ResponseDTO();
            //Will update the method when required
            var vlcMilkCollection = unitOfWork.VLCMilkCollectionRepository.GetById(vLCMilkCollectionDTO.VLCMilkCollectionId);

            //TODO: Make sure what detail need to allow for update - Anil
            vlcMilkCollection.ShiftId            = (int)vLCMilkCollectionDTO.ShiftId;
            vlcMilkCollection.CollectionDateTime = vLCMilkCollectionDTO.CollectionDateTime;
            vlcMilkCollection.CustomerId         = vLCMilkCollectionDTO.CustomerId;
            vlcMilkCollection.VLCId = vLCMilkCollectionDTO.VLCId;

            var customer = unitOfWork.CustomerRepository.GetById(vlcMilkCollection.CustomerId.GetValueOrDefault());

            if (vlcMilkCollection == null)
            {
                throw new PlatformModuleException(string.Format("VLC Milk Collection Detail Not Found with Collection Id {0}", vLCMilkCollectionDTO.VLCMilkCollectionId));
            }
            vlcMilkCollection.ModifiedDate = DateTimeHelper.GetISTDateTime();
            vlcMilkCollection.ModifiedBy   = "Admin";
            //    VLCMilkCollectionConvertor.ConvertToVLCMilkCollectionEntity(ref vlcMilkCollection, vLCMilkCollectionDTO, true);

            var detailList = unitOfWork.VLCMilkCollectionDtlRepository.GetById(vLCMilkCollectionDTO.VLCMilkCollectionId);

            if (detailList != null && detailList.Count() > 0)
            {
                foreach (var collectionDtl in detailList)
                {
                    unitOfWork.VLCMilkCollectionDtlRepository.Delete(collectionDtl.VLCMilkCollectionDtlId);
                }
            }

            if (vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList != null)
            {
                foreach (var vlcCollectionDtlDTO in vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList)
                {
                    VLCMilkCollectionDtl vLCMilkCollectionDtl = new VLCMilkCollectionDtl();
                    vLCMilkCollectionDtl.VLCMilkCollectionDtlId = unitOfWork.DashboardRepository.NextNumberGenerator("VLCMilkCollectionDtl");
                    vLCMilkCollectionDtl.VLCMilkCollectionId    = vlcMilkCollection.VLCMilkCollectionId;
                    VLCMilkCollectionConvertor.ConvertToVLCMilkCollectionDtlEntity(ref vLCMilkCollectionDtl, vlcCollectionDtlDTO, false);
                    //vLCMilkCollectionDtl.RatePerUnit = unitOfWork.MilkRateRepository.GetMilkRateByApplicableRate(customer.ApplicableRate, vlcCollectionDtlDTO.FAT.GetValueOrDefault(), vlcCollectionDtlDTO.CLR.GetValueOrDefault());
                    //vlcCollectionDtlDTO.Amount = vLCMilkCollectionDtl.Amount = vLCMilkCollectionDtl.RatePerUnit * vLCMilkCollectionDtl.Qunatity;

                    unitOfWork.VLCMilkCollectionDtlRepository.Add(vLCMilkCollectionDtl);
                }

                vlcMilkCollection.TotalAmount   = vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList.Sum(s => s.Amount);
                vlcMilkCollection.TotalQuantity = vLCMilkCollectionDTO.vLCMilkCollectionDtlDTOList.Sum(s => s.Quantity);
            }
            else
            {
                throw new PlatformModuleException("VLC Milk Collection Details Not Found");
            }

            unitOfWork.VLCMilkCollectionRepository.Update(vlcMilkCollection);
            unitOfWork.SaveChanges();
            responseDTO.Status  = true;
            responseDTO.Message = String.Format("Milk Collection Detail Updated Successfully");
            ShiftEnum shift;

            Enum.TryParse <ShiftEnum>(vlcMilkCollection.ShiftId.GetValueOrDefault().ToString(), out shift);
            responseDTO.Data = this.GetVLCCustomerCollectionByDateAndShift(vlcMilkCollection.VLCId.GetValueOrDefault(), DateTimeHelper.GetISTDateTime().Date, shift, 1);
            return(responseDTO);
        }