Beispiel #1
0
        public void Create(CreateAdjustmentInput input)
        {
            if (_adjustmentManager.AdjustmentExist(input.RequestDocumentNumber, input.Id, input.CompanyName))
            {
                throw new UserFriendlyException("Existe una solicitud con el mismo numero de Solicitud Fisica.");
            }
            TypeAdjustment temp = (TypeAdjustment)input.TypeAdjustmentValue;


            var requestNumber = GetNextRequestNumber(input.CompanyName);

            var @entityAdjustment = Adjustment.Create(requestNumber, requestNumber.ToString(), input.Notes,
                                                      input.CellarId, AdjustmentStatus.Active, temp, input.CreatorGuidId.Value, _dateTime.Now, input.PersonInCharge, input.CompanyName);

            IList <Detail> @details = new List <Detail>();


            foreach (var item in input.DetailsAdjustment)
            {
                var @entityDetail = Detail.Create(null, null, @entityAdjustment.Id, item.AssetId, item.NameAsset, item.StockAsset, item.Price,
                                                  input.CreatorGuidId.Value, _dateTime.Now, input.CompanyName);
                @details.Add(@entityDetail);
            }

            _adjustmentManager.Create(@entityAdjustment, @details);
        }
Beispiel #2
0
        public void Update(CreateAdjustmentInput input)
        {
            var @entity       = _adjustmentRepository.Get(input.Id);
            var @entityDetail = _adjustmentManager.GetEditDetails(input.Id).ToList();

            if (@entity == null)
            {
                throw new UserFriendlyException("No se pudo encontrar la Bodega, fue borrada o no existe.");
            }
            if (_adjustmentManager.AdjustmentExist(@entity.RequestDocumentNumber, input.Id, input.CompanyName))
            {
                throw new UserFriendlyException("Existe una Bodega con el mismo Nombre.");
            }
            IList <Detail> newDetails    = new List <Detail>();
            IList <Detail> updateDetails = new List <Detail>();

            //@entity.RequestDocumentNumber = ;
            @entity.TypeAdjustment       = (TypeAdjustment)input.TypeAdjustmentValue;
            @entity.LastModificationTime = _dateTime.Now;
            @entity.LastModifierUserId   = input.CreatorUserId;
            @entity.PersonInCharge       = input.PersonInCharge;

            foreach (var item in input.DetailsAdjustment)
            {
                if (@entityDetail.Exists(a => a.AssetId == item.AssetId))
                {
                    var @updateEntity = @entityDetail.FirstOrDefault(a => a.AssetId == item.AssetId);
                    if (item.Delete == 1)
                    {
                        if (item.Saved == 1)
                        {
                            @updateEntity.IsDeleted = true;
                            updateDetails.Add(@updateEntity);
                        }
                    }
                    else if (item.Update == 1)
                    {
                        @updateEntity.Price                = item.Price;
                        @updateEntity.NameAsset            = item.NameAsset;
                        @updateEntity.StockAsset           = item.StockAsset;
                        @updateEntity.LastModificationTime = _dateTime.Now;
                        @updateEntity.LastModifierUserId   = input.CreatorUserId;
                        updateDetails.Add(@updateEntity);
                    }
                }
                else
                {
                    var @createDetail = Detail.Create(null, null, input.Id, item.AssetId, item.NameAsset, item.StockAsset, item.Price,
                                                      input.CreatorUserId, _dateTime.Now, input.CompanyName);
                    newDetails.Add(@createDetail);
                }
            }
            _adjustmentManager.Update(@entity, newDetails, updateDetails);
        }
        public void Create(CreateInRequestInput input)
        {
            //if (_inRequestManager.InRequestExist(input.RequestDocumentNumber, input.Id, input.CompanyName))
            //{
            //    throw new UserFriendlyException("Existe una solicitud con el mismo numero de Solicitud Fisica.");
            //}
            TypeInRequest   temp = (TypeInRequest)input.TypeInRequestValue;
            InRequestStatus temp1;

            temp1 = InRequestStatus.Active;

            var requestNumber = GetNextRequestNumber(input.CompanyName);

            var @entityInRequest = InRequest.Create(requestNumber, requestNumber.ToString(), input.PurchaseOrderNumber, input.Notes, null,
                                                    input.CellarId, temp1, temp, input.CreatorGuidId.Value, _dateTime.Now, input.PersonInCharge, input.CompanyName, input.Comment);

            IList <Detail> @details = new List <Detail>();

            foreach (var item in input.DetailsRequest)
            {
                var @entityDetail = Detail.Create(@entityInRequest.Id, null, null, item.AssetId, item.NameAsset, item.StockAsset, Double.Parse(item.Price),
                                                  input.CreatorGuidId.Value, _dateTime.Now, input.CompanyName);
                @details.Add(@entityDetail);
            }

            if (HasFile(input.Image1))
            {
                string folderPath = "~/InRequestImages/";
                string fileName   = input.Image1.FileName;//input.Id + ".png"

                var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName;
                var directory  = new DirectoryInfo(HostingEnvironment.MapPath(folderPath));
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                string folderPathRelative = "../../InRequestImages/";
                input.ImagePath1 = folderPathRelative + fileName;
                input.Image1.SaveAs(mappedPath);

                @entityInRequest.SetImage1(input.ImagePath1);
            }

            if (HasFile(input.Image2))
            {
                string folderPath = "~/InRequestImages/";
                string fileName   = input.Image2.FileName;//input.Id + ".png"

                var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName;
                var directory  = new DirectoryInfo(HostingEnvironment.MapPath(folderPath));
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                string folderPathRelative = "../../InRequestImages/";
                input.ImagePath2 = folderPathRelative + fileName;
                input.Image2.SaveAs(mappedPath);

                @entityInRequest.SetImage2(input.ImagePath2);
            }
            if (!string.IsNullOrEmpty(input.SignatureData))
            {
                @entityInRequest.SetSignatureData(input.SignatureData);
            }

            _inRequestManager.Create(@entityInRequest, @details);
        }
        public void Update(CreateInRequestInput input)
        {
            var @entity       = _inRequestRepository.Get(input.Id);
            var @entityDetail = _inRequestManager.GetEditDetails(input.Id).ToList();

            if (@entity == null)
            {
                throw new UserFriendlyException("No se pudo encontrar la Ubicación, fue borrada o no existe.");
            }
            //if (_inRequestManager.InRequestExist(@entity.RequestDocumentNumber, input.Id,input.CompanyName))
            //{
            //    throw new UserFriendlyException("Existe una Ubicación con el mismo Nombre.");
            //}
            IList <Detail> newDetails    = new List <Detail>();
            IList <Detail> updateDetails = new List <Detail>();

            //@entity.RequestDocumentNumber = input.RequestDocumentNumber;
            //@entity.AssetsReturnDate = input.AssetsReturnDate;
            @entity.TypeInRequest        = (TypeInRequest)input.TypeInRequestValue;
            @entity.Status               = (InRequestStatus)input.StateRequest;
            @entity.ProjectId            = input.ProjectId;
            @entity.LastModificationTime = _dateTime.Now;
            @entity.LastModifierUserId   = input.CreatorUserId;
            @entity.Notes          = input.Notes;
            @entity.PersonInCharge = input.PersonInCharge;

            foreach (var item in input.DetailsRequest)
            {
                if (@entityDetail.Exists(a => a.AssetId == item.AssetId))
                {
                    var @updateEntity = @entityDetail.Where(a => a.AssetId == item.AssetId).FirstOrDefault();
                    if (item.Delete == 1)
                    {
                        if (item.Saved == 1)
                        {
                            @updateEntity.IsDeleted = true;
                            updateDetails.Add(@updateEntity);
                        }
                    }
                    else if (item.Update == 1)
                    {
                        @updateEntity.Price                = Double.Parse(item.Price);
                        @updateEntity.NameAsset            = item.NameAsset;
                        @updateEntity.StockAsset           = item.StockAsset;
                        @updateEntity.LastModificationTime = _dateTime.Now;
                        @updateEntity.LastModifierUserId   = input.CreatorUserId;
                        updateDetails.Add(@updateEntity);
                    }
                }
                else
                {
                    var @createDetail = Detail.Create(input.Id, null, null, item.AssetId, item.NameAsset, item.StockAsset, Double.Parse(item.Price),
                                                      input.CreatorUserId, _dateTime.Now, input.CompanyName);
                    newDetails.Add(@createDetail);
                }
            }

            if (HasFile(input.Image1))
            {
                string folderPath = "~/InRequestImages/";
                string fileName   = input.Image1.FileName;//input.Id + ".png"

                var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName;
                var directory  = new DirectoryInfo(HostingEnvironment.MapPath(folderPath));
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                string folderPathRelative = "../../InRequestImages/";
                input.ImagePath1 = folderPathRelative + fileName;
                input.Image1.SaveAs(mappedPath);

                @entity.SetImage1(input.ImagePath1);
            }

            if (HasFile(input.Image2))
            {
                string folderPath = "~/InRequestImages/";
                string fileName   = input.Image2.FileName;//input.Id + ".png"

                var mappedPath = HostingEnvironment.MapPath(folderPath) + fileName;
                var directory  = new DirectoryInfo(HostingEnvironment.MapPath(folderPath));
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                string folderPathRelative = "../../InRequestImages/";
                input.ImagePath2 = folderPathRelative + fileName;
                input.Image2.SaveAs(mappedPath);

                @entity.SetImage2(input.ImagePath2);
            }
            if (!string.IsNullOrEmpty(input.SignatureData))
            {
                @entity.SetSignatureData(input.SignatureData);
            }

            _inRequestManager.Update(@entity, newDetails, updateDetails);
        }