Beispiel #1
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <RMARequest, RMARequestViewModel>();
                cfg.CreateMap <RMACase, RMACaseViewModel>();
            });

            IMapper mapper = config.CreateMapper();

            var rmaRequest = await _context.RMARequests
                             .Include(x => x.RMACases)
                             .Include(x => x.Attachments)
                             .Include(x => x.SubmittedByUser)
                             .Select(x => mapper.Map <RMARequest, RMARequestViewModel>(x))
                             .FirstOrDefaultAsync(m => m.Id == id);

            rmaRequest.RMARequestItems = new List <RMARequestItemViewModel>();
            var partSerialNumbers = rmaRequest.PartSerialNumbers.Split(';');

            foreach (var partSerialNumber in partSerialNumbers)
            {
                if (!string.IsNullOrEmpty(partSerialNumber))
                {
                    var keyPair = partSerialNumber.Split(',');
                    rmaRequest.RMARequestItems.Add(new RMARequestItemViewModel
                    {
                        PartNumber   = keyPair[0],
                        SerialNumber = keyPair[1]
                    });
                }
            }

            rmaRequest.RMACases = new List <RMACaseViewModel>();
            var rmaCases = _context.RMACases.Where(x => x.RMARequestId == id)
                           .Include(x => x.RMARequest)
                           .Include(x => x.ProcessedByUser)
                           .Include(x => x.RMAStages)
                           .Select(x => mapper.Map <RMACase, RMACaseViewModel>(x))
                           .ToList();

            rmaRequest.RMACases = rmaCases;

            if (rmaRequest == null)
            {
                return(NotFound());
            }

            RMARequest = rmaRequest;

            return(Page());
        }
        public async Task <IActionResult> OnPostSaveRequestAsync([FromBody] RMARequestViewModel data)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var rmaRequest = _context.RMARequests.FirstOrDefault(x => x.Id == data.Id);

            rmaRequest.CustomerERPId        = data.CustomerERPId;
            rmaRequest.CustomerName         = data.CustomerName;
            rmaRequest.CustomerContactEmail = data.CustomerContactEmail;
            rmaRequest.DefectPhenomenon     = data.DefectPhenomenon;
            rmaRequest.CustomerContact      = data.CustomerContact;
            rmaRequest.InvoiceNumber        = data.InvoiceNumber;
            rmaRequest.Remark = data.Remark;
            //rmaRequest.Status = data.Status;
            rmaRequest.RMAReport         = data.RMAReport;
            rmaRequest.SalesPersonUserId = data.SalesPersonUserId;

            if (rmaRequest.RMANumber == null && data.RMANumber != null)
            {
                rmaRequest.RMANumber = data.RMANumber;
                rmaRequest.RMANumberIssuedByUserId = user.Id;
                rmaRequest.RMAIssueDate            = DateTime.UtcNow;
            }

            // prepare partnumbers & serialnumbers
            rmaRequest.PartSerialNumbers = string.Empty;
            foreach (var item in data.RMARequestItems)
            {
                if (!string.IsNullOrEmpty(item.PartNumber) && !string.IsNullOrEmpty(item.SerialNumber))
                {
                    rmaRequest.PartSerialNumbers += item.PartNumber + "," + item.SerialNumber + ";";
                }
            }

            _context.SaveChanges();

            // Set TempData for notification manually
            AlertViewModel alert = new AlertViewModel
            {
                AlertType  = "success",
                AlertTitle = "You are redirected!",
                AlertBody  = string.Format("RMA Number: {0} with Id: {1} modified successfully.", rmaRequest.RMANumber, rmaRequest.Id)
            };

            TempData.Put <AlertViewModel>("alert", alert);
            return(new JsonResult(string.Format("RMA Number: {0} with Id: {1} modified successfully.", rmaRequest.RMANumber, rmaRequest.Id)));
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostSaveCasesAsync([FromBody] RMARequestViewModel data)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = "Error! Saving RMA Cases not completed.";

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            foreach (var detail in data.RMACases)
            {
                if (string.IsNullOrEmpty(detail.Id))
                {
                    var rmaCase = new RMACase
                    {
                        //Id = detail.Id,
                        RMARequestId       = data.Id,
                        CustomerPartNumber = detail.CustomerPartNumber,
                        PartNumber         = detail.PartNumber,
                        Quantity           = detail.Quantity,
                        InvoiceNumber      = detail.InvoiceNumber,
                        WarrantyStatus     = detail.WarrantyStatus,
                        RMALocation        = detail.RMALocation,
                        Remark             = detail.Remark,
                        RMACaseStatus      = detail.RMACaseStatus,
                        ProcessedByUserId  = user.Id,
                        ProcessedDate      = DateTime.UtcNow,
                        RMAStages          = new List <RMAStage>(),
                        Attachments        = new List <FileAttachment>()
                    };
                    _context.RMACases.Add(rmaCase);
                }
                else
                {
                    var rmaCase = _context.RMACases.FirstOrDefault(x => x.Id == detail.Id);
                    rmaCase.InvoiceNumber      = detail.InvoiceNumber;
                    rmaCase.CustomerPartNumber = detail.CustomerPartNumber;
                    rmaCase.PartNumber         = detail.PartNumber;
                    rmaCase.Quantity           = detail.Quantity;
                    rmaCase.Remark             = detail.Remark;
                    rmaCase.RMACaseStatus      = detail.RMACaseStatus;
                    rmaCase.RMALocation        = detail.RMALocation;
                    rmaCase.WarrantyStatus     = detail.WarrantyStatus;
                    rmaCase.ProcessedByUserId  = user.Id;
                    rmaCase.ProcessedDate      = DateTime.UtcNow;
                }
            }
            // remove original cases not included in this post
            var cases = _context.RMACases.Where(x => x.RMARequestId == data.Id).ToList();

            foreach (var c in cases)
            {
                if (!data.RMACases.Any(x => x.Id == c.Id))
                {
                    _context.RMACases.Remove(c);
                }
            }
            _context.SaveChanges();

            result = "Success! Save RMA Cases are completed.";

            return(new JsonResult(result));
        }
        public async Task <IActionResult> OnPostSaveRequestAsync([FromBody] RMARequestViewModel data)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var rmaRequest = new RMARequest
            {
                CustomerERPId        = data.CustomerERPId,
                CustomerName         = data.CustomerName,
                CustomerContactEmail = data.CustomerContactEmail,
                CustomerContact      = data.CustomerContact,
                DefectPhenomenon     = data.DefectPhenomenon,
                Remark            = data.Remark,
                InvoiceNumber     = data.InvoiceNumber,
                SalesPersonUserId = data.SalesPersonUserId,
                Status            = data.Status,
                RMAReport         = data.RMAReport,
                RMANumber         = data.RMANumber,
                Attachments       = new List <FileAttachment>(),
                SubmittedByUserId = user.Id,
                SubmittedDate     = DateTime.UtcNow,
                RMACases          = new List <RMACase>(),
            };

            // prepare partnumbers & serialnumbers
            foreach (var item in data.RMARequestItems)
            {
                if (!string.IsNullOrEmpty(item.PartNumber) && !string.IsNullOrEmpty(item.SerialNumber))
                {
                    rmaRequest.PartSerialNumbers += item.PartNumber + "," + item.SerialNumber + ";";
                }
            }

            if (data.RMANumber != null)
            {
                if (data.RMAIssueDate == null)
                {
                    rmaRequest.RMAIssueDate = DateTime.UtcNow;
                }
            }

            _context.RMARequests.Add(rmaRequest);
            _context.SaveChangesAsync().Wait();

            // Set TempData for notification manually
            AlertViewModel alert = new AlertViewModel
            {
                AlertType  = "success",
                AlertTitle = "You are redirected!",
                AlertBody  = string.Format("RMAId: {0} created.", rmaRequest.Id)
            };

            TempData.Put <AlertViewModel>("alert", alert);
            return(new JsonResult(string.Format("RMAId: {0} created.", rmaRequest.Id)));
            //return RedirectToPage("./RMARequestsIndex")
            //    .WithSuccess("You are redirected!",
            //    string.Format("RMAId: {0} created.", rmaRequest.Id));
        }
        public async Task <IActionResult> OnPostCloseRMAAsync([FromBody] RMARequestViewModel data)
        {
            var id = data.Id;

            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var rmaRequest = _context.RMARequests.Include(x => x.RMACases)
                             .FirstOrDefault(x => x.Id == id && x.Status != RMAStatus.Closed);

            if (rmaRequest == null)
            {
                return(NotFound());
            }

            if (rmaRequest.RMACases.Count == 0)
            {
                return(NotFound());
            }

            bool isValidToClose = true;

            foreach (var rmaCase in rmaRequest.RMACases)
            {
                var stages = _context.RMAStages.Where(x => x.RMACaseId == rmaCase.Id).ToList();

                foreach (var stage in stages)
                {
                    isValidToClose = stage.IsActionDone;
                    if (!isValidToClose)
                    {
                        break;
                    }
                }
                if (!isValidToClose)
                {
                    break;
                }
            }

            AlertViewModel alert = new AlertViewModel();

            if (isValidToClose)
            {
                rmaRequest.Status            = RMAStatus.Closed;
                rmaRequest.RMAClosedDate     = DateTime.UtcNow;
                rmaRequest.RMAClosedByUserId = user.Id;
                _context.SaveChanges();
            }
            else
            {
                // Set TempData for notification manually
                alert = new AlertViewModel
                {
                    AlertType  = "warning",
                    AlertTitle = "You have not done stage.",
                    AlertBody  = string.Format("RMA Number: {0} with Id: {1} modified failed.", rmaRequest.RMANumber, rmaRequest.Id)
                };

                return(NotFound());
            }

            // Set TempData for notification manually
            alert = new AlertViewModel
            {
                AlertType  = "success",
                AlertTitle = "You are redirected!",
                AlertBody  = string.Format("RMA Number: {0} with Id: {1} modified successfully.", rmaRequest.RMANumber, rmaRequest.Id)
            };

            TempData.Put <AlertViewModel>("alert", alert);
            return(new JsonResult(string.Format("RMA Number: {0} with Id: {1} modified successfully.", rmaRequest.RMANumber, rmaRequest.Id)));
        }