예제 #1
0
        public HttpResponseMessage UpdateShipment(ClientLoadCustomModel model)
        {
            using (ClientLoadService clservice = new ClientLoadService())
            {
                clservice.CurrentUser = clservice.GetUser(model.Email);

                ClientLoad load = clservice.GetById(model.Id);

                if (load == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel()
                    {
                        Code = -1, Description = "Shipment could not be found"
                    }));
                }

                //load.OutstandingReasonId = null;
                load.PCNNumber = model.PCNNumber;
                load.PODNumber = model.PODNumber;
                load.PRNNumber = model.PRNNumber;

                load.PCNCommentDate = DateTime.Now;
                load.PODCommentDate = DateTime.Now;
                load.PRNCommentDate = DateTime.Now;

                load.PCNComments = model.PCNComments;
                load.PODComments = model.PODComments;
                load.PRNComments = model.PRNComments;

                load.PODStatus = ( int )Status.Active;

                load.PODCommentById = clservice.CurrentUser.Id;
                load.PCNCommentById = clservice.CurrentUser.Id;
                load.PRNCommentById = clservice.CurrentUser.Id;

                clservice.Update(load);

                CustomSearchModel csm = new CustomSearchModel();

                PagingModel pm = new PagingModel()
                {
                    SortBy = "cl.PCNNumber, cl.PRNNumber, cl.PODNumber"
                };

                List <ClientLoadCustomModel> loads = clservice.ListOutstandingShipments(pm, csm);

                return(Request.CreateResponse(HttpStatusCode.OK, new { OutstandingShipments = loads, Code = 1, Description = "Shipment updated" }));
            }
        }
        public ActionResult EditClientLoad(ClientLoadViewModel model, PagingModel pm, CustomSearchModel csm)
        {
            using (ImageService iservice = new ImageService())
                using (ClientLoadService clservice = new ClientLoadService())
                {
                    ClientLoad load = clservice.GetById(model.Id);

                    if (load == null)
                    {
                        Notify("Sorry, the requested resource could not be found. Please try again", NotificationType.Error);

                        return(PartialView("_AccessDenied"));
                    }

                    #region Update Client Load

                    load.PODNumber = model.PODNumber;
                    load.PCNNumber = model.PCNNumber;
                    load.PRNNumber = model.PRNNumber;

                    load.PODCommentDate = DateTime.Now;
                    load.PCNCommentDate = DateTime.Now;
                    load.PRNCommentDate = DateTime.Now;

                    load.PODCommentId = model.PODCommentId;
                    load.PCNComments  = model.PCNComments;
                    load.PRNComments  = model.PRNComments;

                    load.PODCommentById = CurrentUser.Id;
                    load.PCNCommentById = CurrentUser.Id;
                    load.PRNCommentById = CurrentUser.Id;

                    clservice.Update(load);

                    #endregion

                    #region Any Uploads?

                    if (model.Files.NullableAny(f => f.File != null))
                    {
                        // Create folder
                        string path = Server.MapPath($"~/{VariableExtension.SystemRules.ImagesLocation}/ClientLoad/{load.LoadNumber?.Trim()}/");

                        string now = DateTime.Now.ToString("yyyyMMddHHmmss");

                        foreach (FileViewModel f in model.Files.Where(f => f.File != null))
                        {
                            string ext = Path.GetExtension(f.File.FileName),
                                               name = f.File.FileName.Replace(ext, "");

                            // Check if a logo already exists?
                            Image img = iservice.Get(load.Id, f.Name, true);

                            if (img != null)
                            {
                                DeleteImage(img.Id);
                            }

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            Image image = new Image()
                            {
                                Name       = name,
                                IsMain     = true,
                                Extension  = ext,
                                ObjectId   = load.Id,
                                ObjectType = f.Name,
                                Size       = f.File.ContentLength,
                                Location   = $"ClientLoad/{load.LoadNumber?.Trim()}/{now}-{f.File.FileName}"
                            };

                            iservice.Create(image);

                            string fullpath = Path.Combine(path, $"{now}-{f.File.FileName}");

                            f.File.SaveAs(fullpath);
                        }
                    }

                    #endregion
                }

            Notify("The selected Client Load details were successfully updated.", NotificationType.Success);

            return(PODManagement(pm, csm));
        }
        public ActionResult EditClientLoad(int id)
        {
            using (ImageService iservice = new ImageService())
                using (ClientLoadService clservice = new ClientLoadService())
                {
                    ClientLoad load = clservice.GetById(id);

                    if (load == null)
                    {
                        Notify("Sorry, the requested resource could not be found. Please try again", NotificationType.Error);

                        return(PartialView("_AccessDenied"));
                    }

                    ClientLoadViewModel model = new ClientLoadViewModel()
                    {
                        Id           = load.Id,
                        EditMode     = true,
                        PODNumber    = load.PODNumber,
                        PCNNumber    = load.PCNNumber,
                        PRNNumber    = load.PRNNumber,
                        PODCommentId = load.PODCommentId,
                        PCNComments  = load.PCNComments,
                        PRNComments  = load.PRNComments,
                        Files        = new List <FileViewModel>()
                    };

                    Image podImg = iservice.Get(model.Id, "PODNumber", true);
                    Image pcnImg = iservice.Get(model.Id, "PCNNumber", true);
                    Image prnImg = iservice.Get(model.Id, "PRNNumber", true);

                    if (podImg != null)
                    {
                        model.Files.Add(new FileViewModel()
                        {
                            Id        = podImg.Id,
                            Name      = "PODNumber",
                            Extension = podImg.Extension
                        });
                    }

                    if (pcnImg != null)
                    {
                        model.Files.Add(new FileViewModel()
                        {
                            Id        = pcnImg.Id,
                            Name      = "PCNNumber",
                            Extension = pcnImg.Extension
                        });
                    }

                    if (prnImg != null)
                    {
                        model.Files.Add(new FileViewModel()
                        {
                            Id        = prnImg.Id,
                            Name      = "PRNNumber",
                            Extension = prnImg.Extension
                        });
                    }

                    return(View(model));
                }
        }
예제 #4
0
        public HttpResponseMessage UploadShipment(int id, string apikey, string objecttype, string comment, string email)
        {
            try
            {
                using (ImageService iservice = new ImageService())
                    using (ClientLoadService saservice = new ClientLoadService())
                    {
                        saservice.CurrentUser = saservice.GetUser(email);

                        ClientLoad load = saservice.GetById(id);

                        if (load == null)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel()
                            {
                                Code = -1, Description = "Shipment could not be found"
                            }));
                        }

                        HttpPostedFile file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;

                        if (file == null)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel()
                            {
                                Code = -1, Description = "No file uploaded!"
                            }));
                        }

                        // Create folder
                        string path = HostingEnvironment.MapPath($"~/{VariableExtension.SystemRules.ImagesLocation}/ClientLoad/{load.LoadNumber?.Trim()}/");

                        string now = DateTime.Now.ToString("yyyyMMddHHmmss");

                        string ext  = Path.GetExtension(file.FileName),
                               name = file.FileName.Replace(ext, "");

                        // Check if a logo already exists?
                        Image img = iservice.Get(load.Id, objecttype, true);

                        if (img != null)
                        {
                            baseC.DeleteImage(img.Id);
                        }

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        Image image = new Image()
                        {
                            Name        = name,
                            ObjectId    = load.Id,
                            ObjectType  = objecttype,
                            Size        = file.ContentLength,
                            Description = comment,
                            IsMain      = true,
                            Extension   = ext,
                            Location    = $"ClientLoad/{load.LoadNumber?.Trim()}/{now}-{file.FileName}"
                        };

                        iservice.Create(image);

                        string fullpath = Path.Combine(path, $"{now}-{file.FileName}");

                        file.SaveAs(fullpath);

                        return(Request.CreateResponse(HttpStatusCode.OK, saservice.OldObject));
                    }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, ex.Message.ToString()));
            }
        }