示例#1
0
 public IActionResult Edit(int id, [FromBody] SupplierDetailsVM model)
 {
     if (ModelState.IsValid)
     {
         string user = User.Identity.Name;
         model.Id = id;
         int newSupplierId = _supplierService.EditSupplier(model, user);
         return(CreatedAtAction(nameof(GetDetails), new { id = newSupplierId }, model));
     }
     return(BadRequest());
 }
示例#2
0
        public ActionResult CreateEdit(USupplier supplier, string Action = "")
        {
            if (ModelState.IsValid)
            {
                // save log file
                if (supplier.Logo != null && supplier.Logo.ContentLength > 0)
                {
                    string path;
                    var    fileName = Path.GetFileName(supplier.Logo.FileName);
                    if (Action.Equals("Edit") && !string.IsNullOrWhiteSpace(supplier.LogoLocation))
                    {
                        path = Path.Combine(Server.MapPath("~/App_Data/Logos"), supplier.LogoLocation);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }

                    path = Path.Combine(Server.MapPath("~/App_Data/Logos"), fileName);
                    supplier.Logo.SaveAs(path);
                    supplier._Supplier.LogoLocation = fileName;
                }

                supplier._Supplier.CountryProgrammeId = countryProg.Id;
                supplier._Supplier.IsApproved         = true;

                if (Action.Equals("Edit"))
                {
                    if (supplierService.EditSupplier(supplier._Supplier))
                    {
                        ModelState.Clear();
                        supplier = new USupplier();
                    }
                }
                else
                {
                    if (supplierService.AddSupplier(supplier._Supplier))
                    {
                        ModelState.Clear();
                        supplier = new USupplier();
                    }
                }
            }
            supplier.CountrySelect = new SelectList(supplierService.CountryService.GetCountries(), "Id", "Name");
            return(ListView());
        }
示例#3
0
        public IActionResult EditSupplier(SupplierDetailsVM model)
        {
            int supplierId = 0;

            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    supplierId = _supplierService.AddSupplier(model, User.Identity.Name);
                }
                else
                {
                    supplierId = _supplierService.EditSupplier(model, User.Identity.Name);
                }
                return(RedirectToAction("SupplierDetails", new { id = supplierId }));
            }
            return(View(model));
        }