Ejemplo n.º 1
0
        public ActionResult CreateFreight(FreightModel FreightModel1)
        {
            if (ModelState.IsValid)
            {
                FreightModel1.UserId     = User1.Id;
                FreightModel1.CreateDate = DateTime.Now.ToString("dd/MM/yyyy");
                FreightModel1.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy");

                if (FreightModel.FreightTypes.OceanFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.SeaInbound.ToString();
                }
                else if (FreightModel.FreightTypes.AirFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.AirInbound.ToString();
                }
                else if (FreightModel.FreightTypes.InlandRates.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.InlandService.ToString();
                }
                else
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.Other.ToString();
                }
                FreightModel1.ServiceId = servicesType.GetId(FreightModel1.ServiceName);
                Freight Freight1 = _freightService.CreateFreight(FreightModel1);
                if (Freight1 != null)
                {
                    foreach (string inputTagName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[inputTagName];
                        if (file.ContentLength > 0)
                        {
                            string filePath = Path.Combine(Server.MapPath("~/" + FREIGHT_PATH)
                                                           , Path.GetFileName(file.FileName));
                            file.SaveAs(filePath);
                            //save file to db
                            ServerFile ServerFile1 = new ServerFile();
                            ServerFile1.ObjectId     = Freight1.Id;
                            ServerFile1.ObjectType   = Freight1.GetType().ToString();
                            ServerFile1.Path         = FREIGHT_PATH + "/" + file.FileName;
                            ServerFile1.FileName     = file.FileName;
                            ServerFile1.FileSize     = file.ContentLength;
                            ServerFile1.FileMimeType = file.ContentType;
                            _freightService.insertServerFile(ServerFile1);
                        }
                    }
                }
                return(RedirectToAction("ListFreight", new { Id = 0, FreightType = FreightModel1.Type }));
            }
            else
            {
                IEnumerable <Area> AreaListDep = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDep);
                IEnumerable <Area> AreaListDes = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDes);
                ViewData["AreaListDep"]  = new SelectList(AreaListDep, "Id", "AreaAddress");
                ViewData["AreaListDes"]  = new SelectList(AreaListDes, "Id", "AreaAddress");
                ViewData["FreightTypes"] = FreightTypes;
            }
            return(View(FreightModel1));
        }
Ejemplo n.º 2
0
        private void viewServerFiles(Freight Freight1)
        {
            IEnumerable <ServerFile> ServerFiles = _freightService.getServerFile(Freight1.Id, Freight1.GetType().ToString());

            ViewData["ServerFiles"] = ServerFiles;
        }