Beispiel #1
0
        public void UpdateInstructionTemplate([FromUri] int templateId, [FromBody] InstructionTemplateDto template)
        {
            var templateInDb = _context.InstructionTemplates.Find(templateId);

            templateInDb.Description          = template.Description;
            templateInDb.IsInstruction        = template.IsInstruction;
            templateInDb.IsOperation          = template.IsOperation;
            templateInDb.IsCharging           = template.IsCharging;
            templateInDb.IsApplyToMasterOrder = template.IsApplyToMasterOrder;
            templateInDb.IsApplyToShipOrder   = template.IsApplyToShipOrder;
            templateInDb.Status = template.IsCharging ? FBAStatus.WaitingForCharging : FBAStatus.NoNeedForCharging;

            _context.SaveChanges();
        }
Beispiel #2
0
        public IHttpActionResult CreateNewChargingDetailTemplateByModel([FromUri] int customerId, [FromBody] InstructionTemplateDto template)
        {
            var fbaCustomers = _context.UpperVendors
                               .Where(x => x.DepartmentCode == "FBA");

            if (!template.IsApplyToAll)
            {
                var newTemplate = new InstructionTemplate
                {
                    IsApplyToMasterOrder = template.IsApplyToMasterOrder,
                    IsApplyToShipOrder   = template.IsApplyToShipOrder,
                    IsInstruction        = template.IsInstruction,
                    IsOperation          = template.IsOperation,
                    IsCharging           = template.IsCharging,
                    CreateBy             = _userName,
                    Description          = template.Description,
                    CreateDate           = DateTime.Now,
                    Status = template.IsCharging ? FBAStatus.WaitingForCharging : FBAStatus.NoNeedForCharging
                };

                var customerInDb = fbaCustomers.SingleOrDefault(x => x.Id == customerId);
                newTemplate.Customer = customerInDb;

                _context.InstructionTemplates.Add(newTemplate);
            }
            else
            {
                var templateList = new List <InstructionTemplate>();

                foreach (var f in fbaCustomers)
                {
                    var newTemplate = new InstructionTemplate
                    {
                        IsApplyToMasterOrder = template.IsApplyToMasterOrder,
                        IsApplyToShipOrder   = template.IsApplyToShipOrder,
                        IsInstruction        = template.IsInstruction,
                        IsOperation          = template.IsOperation,
                        IsCharging           = template.IsCharging,
                        CreateBy             = _userName,
                        Description          = template.Description,
                        CreateDate           = DateTime.Now,
                        Status = template.IsCharging ? FBAStatus.WaitingForCharging : FBAStatus.NoNeedForCharging
                    };

                    newTemplate.Customer = f;
                    templateList.Add(newTemplate);
                }

                _context.InstructionTemplates.AddRange(templateList);
            }

            _context.SaveChanges();

            var resultDto = Mapper.Map <ChargingItemDetail, ChargingItemDetailDto>(_context.ChargingItemDetails.OrderByDescending(x => x.Id).First());

            return(Created(Request.RequestUri + "/" + resultDto.Id, resultDto));
        }