示例#1
0
        private SupplierDTO Create(SupplierViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierViewModel.FormatSupplierViewModel(viewModel));

                SupplierDTO supplier = new SupplierDTO();

                // copy values
                viewModel.UpdateDTO(supplier, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                supplier.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                supplier.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_supplierService.AddSupplier - " + SupplierDTO.FormatSupplierDTO(supplier));

                int id = _supplierService.AddSupplier(supplier);

                supplier.SupplierId = id;

                log.Debug("result: 'success', id: " + id);

                return(supplier);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
示例#2
0
 public IActionResult Create([FromBody] SupplierDetailsVM model)
 {
     if (ModelState.IsValid)
     {
         string user          = User.Identity.Name;
         int    newSupplierId = _supplierService.AddSupplier(model, user);
         return(CreatedAtAction(nameof(GetDetails), new { id = newSupplierId }, model));
     }
     return(BadRequest());
 }
示例#3
0
 public HttpResponseMessage AddSupplier([FromBody] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         var result = _service.AddSupplier(supplier);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
示例#4
0
        public async Task <IActionResult> AddSupplier([FromBody] Supplier supplier)
        {
            try
            {
                var data = await _supplierService.AddSupplier(supplier);

                return(Ok(data));
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Error report generate {@supplier} on {AddSupplier}", supplier, DateTime.Now);
                throw exception;
            }
        }
 public ActionResult Add(SupplierVM mSupplierVm)
 {
     if (ModelState.IsValid)
     {
         var sup = new Supplier();
         if (TryUpdateModel(sup))
         {
             if (ExecuteRepositoryAction(() => { _svc.AddSupplier(sup); _svc.CommitChanges(); }))
             {
                 return(ReturnJsonFormSuccess());
             }
         }
     }
     return(PartialView("Edit", mSupplierVm));
 }
示例#6
0
        static void AddSuppliers(ISupplierService supplierService)
        {
            Console.WriteLine("Adding suppliers ... ");

            // Add three suppliers
            for (int i = 1; i <= 3; i++)
            {
                supplierService.AddSupplier(new Supplier()
                {
                    Id   = i,
                    Name = $"Supplier{i}"
                });
            }

            Console.WriteLine("Suppliers added");
        }
示例#7
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());
        }
示例#8
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));
        }
示例#9
0
        public ActionResult AddNewSupplier4PO(USupplier model)
        {
            Supplier supplier = null;

            supplier = supplierService.GetSupplierByName(model.Name, countryProg.Id);
            if (supplier == null)
            {
                supplier                    = new Supplier();
                supplier.Name               = model.Name;
                supplier.Address            = model.Address != null && model.Address.Trim().Length > 0 ? model.Address : Resources.SystemUser_ViewProfile_NotSet.ToUpper();
                supplier.PrimaryPhone       = model.PrimaryPhone != null && model.PrimaryPhone.Trim().Length > 0 ? model.PrimaryPhone : Resources.SystemUser_ViewProfile_NotSet.ToUpper();
                supplier.CountryId          = countryProg.CountryId;
                supplier.CountryProgrammeId = countryProg.Id;
                supplier.IsApproved         = false;
                supplierService.AddSupplier(supplier);
            }
            return(RepopulateSupplierList(supplier.Id));
        }
        public async Task <IActionResult> Post([FromBody] SupplierBindingModel model)
        {
            var supplier = await _supplierService.AddSupplier(_mapper.Map <Supplier>(model));

            return(Ok(_mapper.Map <SupplierBindingModel>(supplier)));
        }
示例#11
0
        public async Task <IActionResult> InsertSupplier([FromBody] SupplierInsertModel model)
        {
            var result = await _supplierService.AddSupplier(model);

            return(ApiResponder.RespondSuccess(result));
        }
示例#12
0
        public ActionResult Add(SupplierDto supplierDto)
        {
            var currentUser = Session["LogUser"] as UserDto;

            return(Json(_supplierService.AddSupplier(supplierDto, currentUser)));
        }