예제 #1
0
        public ActionResult Create(SupplierViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var contact = vm.Contact.ToModel();
                var admin = vm.Admin.ToModel();
                _contacts.Save(contact);
                _contacts.Save(admin);
                var supplier = vm.ToModel();
                supplier.AdminId = admin.Id;
                supplier.ContactId = contact.Id;
                _suppliers.Save(supplier);
                return RedirectToAction("Index");
            }

            return View(vm);
        }
예제 #2
0
        public async Task <ResponseViewModel> SaveSupplier(SupplierViewModel vm)
        {
            var response = new ResponseViewModel();

            try
            {
                var supplier = _db.Suppliers.FirstOrDefault(x => x.Id == vm.Id);

                if (supplier == null)
                {
                    supplier = vm.ToModel();

                    _db.Suppliers.Add(supplier);
                    await _db.SaveChangesAsync();

                    response.IsSuccess = true;
                    response.Message   = "Supplier has been created.";
                }
                else
                {
                    supplier.Name        = vm.Name;
                    supplier.Description = vm.Description;
                    supplier.Address     = vm.Address;
                    supplier.Phone1      = vm.Phone1;
                    supplier.Phone2      = vm.Phone2;
                    supplier.Email1      = vm.Email1;
                    supplier.Email2      = vm.Email2;

                    _db.Suppliers.Update(supplier);
                    await _db.SaveChangesAsync();

                    response.IsSuccess = true;
                    response.Message   = "Supplier has been updated.";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error has been occured.";
            }

            return(response);
        }
예제 #3
0
 public ActionResult Edit(SupplierViewModel model)
 {
     if (ModelState.IsValid)
     {
         _contacts.Save(model.Contact.ToModel());
         _contacts.Save(model.Admin.ToModel());
         _suppliers.Save(model.ToModel());
         return RedirectToAction("Index");
     }
     return View(model);
 }