예제 #1
0
        public async Task <IActionResult> UpdateRepairStatusCustomer(int repairId, int statusId)
        {
            var repair = await _repairService.GetRepairByIdAsync(repairId);

            if (repair != null)
            {
                RepairUpdateRequest model = new RepairUpdateRequest();

                model.CustomerId  = repair.CustomerId;
                model.Description = repair.Description;
                model.RepairId    = repair.RepairId;
                model.StatusId    = statusId;
                model.ProductId   = repair.ProductId;

                model.RepairItems = new List <RepairItemAddRequest>();

                foreach (var item in repair.RepairItems)
                {
                    RepairItemAddRequest req = new RepairItemAddRequest()
                    {
                        Quantity     = item.Quantity,
                        RepairId     = repair.RepairId,
                        SaparePartId = item.SaparePart.SaparePartId
                    };

                    model.RepairItems.Add(req);
                }

                return(await UpdateRepairClient(model));
            }

            return(BadRequest());
        }
        public Repair ConvertRepairAddRequestToRepair(RepairUpdateRequest repairUpdateRequest, Repair repair)
        {
            repair.RepairId       = repairUpdateRequest.RepairId;
            repair.Description    = repairUpdateRequest.Description;
            repair.RepairStatusId = repairUpdateRequest.StatusId;
            repair.CustomerId     = repairUpdateRequest.CustomerId;
            repair.ProductId      = repairUpdateRequest.ProductId;
            repair.RepairItems    = Mapper.Map <ICollection <RepairItem> >(repairUpdateRequest.RepairItems);

            return(repair);
        }
예제 #3
0
        public async Task <IActionResult> UpdateRepairClient(RepairUpdateRequest repairUpdateRequest)
        {
            if (ModelState.IsValid)
            {
                await _repairService.UpdateRepairAsync(repairUpdateRequest);

                HttpContext.Session.Clear();
                return(RedirectToAction("DecisionTaken", "Repair", new { repairId = repairUpdateRequest.RepairId }));
            }

            return(BadRequest(ModelState));
        }
예제 #4
0
        public async Task <IActionResult> UpdateRepairStatus(int repairId, int statusId)
        {
            var repair = await _repairService.GetRepairByIdAsync(repairId);

            if (repair != null)
            {
                RepairUpdateRequest model = new RepairUpdateRequest();

                model.CustomerId  = repair.CustomerId;
                model.Description = repair.Description;
                model.RepairId    = repair.RepairId;
                model.StatusId    = statusId;
                model.ProductId   = repair.ProductId;

                var host   = HttpContext.Request.Host.Host;
                var port   = HttpContext.Request.Host.Port;
                var apiUri = host + ":" + port;
                if (port == null)
                {
                    apiUri = host;
                }

                model.Links = new Core.Models.Healpers.CustomerDecisionLink();
                model.Links.DecisionLink = Url.Action("DecisionTaken", "Repair", new { repairId = model.RepairId }, "https", apiUri);

                model.RepairItems = new List <RepairItemAddRequest>();

                foreach (var item in repair.RepairItems)
                {
                    RepairItemAddRequest req = new RepairItemAddRequest()
                    {
                        Quantity     = item.Quantity,
                        RepairId     = repair.RepairId,
                        SaparePartId = item.SaparePart.SaparePartId
                    };

                    model.RepairItems.Add(req);
                }

                return(await UpdateRepair(model));
            }

            return(BadRequest());
        }
예제 #5
0
        public async Task <IActionResult> UpdateRepair(RepairUpdateRequest repairUpdateRequest)
        {
            if (ModelState.IsValid)
            {
                if (repairUpdateRequest.StatusId == 2)
                {
                    foreach (var item in repairUpdateRequest.RepairItems)
                    {
                        item.RepairId = repairUpdateRequest.RepairId;
                    }
                }

                await _repairService.UpdateRepairAsync(repairUpdateRequest);

                HttpContext.Session.Clear();
                return(RedirectToAction("Details", "Repair", new { repairId = repairUpdateRequest.RepairId }));
            }

            return(BadRequest(ModelState));
        }
예제 #6
0
        public async Task UpdateRepairAsync(RepairUpdateRequest repairUpdateRequest)
        {
            _nullCheckMethod.CheckIfRequestIsNull(repairUpdateRequest);

            var repair = await _unitOfWork.Repairs.GetRepairItemByIdAsync(repairUpdateRequest.RepairId);

            _nullCheckMethod.CheckIfResponseIsNull(repair);

            repair = _repairMappingProfile.ConvertRepairAddRequestToRepair(repairUpdateRequest, repair);

            if (repair.RepairStatusId == 1)
            {
                if (repair.RepairItems != null)
                {
                    repair.RepairStatusId = 2;
                }
            }

            await _unitOfWork.CompleteAsync();

            await _emailService.SendRepairStatusNotifyEmailAsync(repairUpdateRequest.RepairId, repairUpdateRequest.Links);
        }
예제 #7
0
        public async Task <IActionResult> UpdateRepair(int?repairId, int?saparepartId, int?quantity)
        {
            RepairDetailsResponse repair = new RepairDetailsResponse();

            if (repairId != null)
            {
                repair = await _repairService.GetRepairByIdAsync(repairId.Value);

                var key  = "currentRepairId";
                var data = repairId.Value;
                HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));
            }

            RepairUpdateRequest model = new RepairUpdateRequest();

            var result = HttpContext.Session.GetString("repairUpdateRequest");

            if (result != null)
            {
                var data            = JsonConvert.DeserializeObject <RepairUpdateRequest>(result);
                var currentRepairId = HttpContext.Session.GetString("currentRepairId");

                if (data.RepairId != int.Parse(currentRepairId))
                {
                    HttpContext.Session.Clear();
                }
            }

            var str = HttpContext.Session.GetString("repairUpdateRequest");

            if (str != null)
            {
                var data = JsonConvert.DeserializeObject <RepairUpdateRequest>(str);
                model = data;
            }
            else
            {
                model.Links = new Core.Models.Healpers.CustomerDecisionLink();
                var host   = HttpContext.Request.Host.Host;
                var port   = HttpContext.Request.Host.Port;
                var apiUri = host + ":" + port;
                if (port == null)
                {
                    apiUri = host;
                }
                model.Links.DecisionLink = Url.Action("CustomerDecision", "Repair", new { repairId = repair.RepairId }, "https", apiUri);

                model.CustomerId  = repair.CustomerId;
                model.Description = repair.Description;
                model.RepairId    = repair.RepairId;
                model.StatusId    = repair.StatusId;
                model.ProductId   = repair.ProductId;

                if (repair.RepairItems.Any() && repair.StatusId != 1)
                {
                    model.RepairItems = new List <RepairItemAddRequest>();

                    foreach (var item in repair.RepairItems)
                    {
                        RepairItemAddRequest req = new RepairItemAddRequest()
                        {
                            Quantity     = item.Quantity,
                            RepairId     = repair.RepairId,
                            SaparePartId = item.SaparePart.SaparePartId
                        };

                        model.RepairItems.Add(req);
                    }
                }
                else
                {
                    model.RepairItems = new List <RepairItemAddRequest>();
                }

                var key  = "repairUpdateRequest";
                var data = model;
                HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));

                var keyCurrentRepairId  = "currentRepairId";
                var dataCurrentRepairId = model.RepairId;
                HttpContext.Session.SetString(keyCurrentRepairId, JsonConvert.SerializeObject(dataCurrentRepairId));
            }

            if (saparepartId != null && quantity != null)
            {
                var repairCurrentData = await _repairService.GetRepairByIdAsync(int.Parse(HttpContext.Session.GetString("currentRepairId")));

                var newRepairItem = new RepairItemAddRequest()
                {
                    RepairId        = model.RepairId,
                    SaparePartId    = saparepartId.Value,
                    Quantity        = quantity.Value,
                    Name            = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.Name).First(),
                    ReferenceNumber = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.ReferenceNumber).First(),
                    Price           = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.Price).First()
                };

                if (model.RepairItems != null)
                {
                    model.RepairItems.Add(newRepairItem);

                    var key  = "repairUpdateRequest";
                    var data = model;
                    HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));
                }

                return(RedirectToAction("UpdateRepair", "Repair", new { repairId = model.RepairId }));
            }

            return(View(model));
        }