Exemple #1
0
        public void AddOrUpdateVendor(VendorVm vendorVm)
        {
            var vendor = Mapper.Map <Vendor>(vendorVm);

            _uow.Repository <Vendor>().AddOrUpdate(x => x.VendorID == vendor.VendorID, vendor);
            _uow.Save();
        }
Exemple #2
0
        public VendorVm GetVendor(Expression <Func <Vendor, bool> > filterPredicate = null)
        {
            Vendor   vendor   = _uow.Repository <Vendor>().Get(filterPredicate, false, null);
            VendorVm vendorVm = Mapper.Map <VendorVm>(vendor);

            return(vendorVm);
        }
        public ActionResult Edit(VendorVm vendorVm)
        {
            try
            {
                var vendor = Db.Vendors.Find(Guid.Parse(vendorVm.Id));
                if (vendor != null)
                {
                    vendor.Name        = vendorVm.Name;
                    vendor.CompanyName = vendorVm.CompanyName;
                    vendor.Email       = vendorVm.Email;
                    vendor.Phone       = vendorVm.Phone;
                    vendor.CcEmails    = vendorVm.CcEmails;
                }
                Db.SaveChanges();
                TempData["Success"] = "Vendor settings has been updated successfully!";

                ForceVendors = true;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                // ignored
            }
            return(View("Error"));
        }
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                throw new HttpException(400, "Bad Request");
            }
            var x = Db.Vendors.Find(id);

            if (x == null)
            {
                throw new HttpException(404, "Not found");
            }
            var vendor = new VendorVm
            {
                Id          = x.Id.ToString(),
                Name        = x.Name,
                CompanyName = x.CompanyName,
                Email       = x.Email,
                CcEmails    = x.CcEmails,
                Phone       = x.Phone,
                DateCreated = x.CreatedAt.ToString()
            };

            return(View("New", vendor));
        }
        public ActionResult New(VendorVm vendorVm)
        {
            try
            {
                var vendor = new Vendor()
                {
                    Id          = Guid.NewGuid(),
                    CreatedAt   = DateTime.Now,
                    CreatedBy   = LoggedInUser.Id,
                    Name        = vendorVm.Name,
                    CompanyName = vendorVm.CompanyName,
                    Email       = vendorVm.Email,
                    CcEmails    = vendorVm.CcEmails,
                    Phone       = vendorVm.Phone,
                };
                Db.Vendors.Add(vendor);
                Db.SaveChanges();

                ForceVendors = true;

                TempData["Success"] = "Vendor settings has been added successfully!";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                //
            }
            return(View("Error"));
        }
        public async Task <IHttpActionResult> PutVendor(int id, VendorVm model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != model.VendorId)
            {
                return(BadRequest());
            }

            _db.Entry(model).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VendorExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PostVendor(VendorVm model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.Vendors.Add(model);
            await _db.SaveChangesAsync();

            var ret = await _db.Vendors.Select(VendorVm.Select).FirstOrDefaultAsync(x => x.VendorId == model.VendorId);

            return(CreatedAtRoute("DefaultApi", new { id = model.VendorId }, model));
        }
Exemple #8
0
        public ActionResult Delete(int id, VendorVm model)
        {
            try
            {
                var vendor = _repo.FindbyId(id);


                if (vendor == null)
                {
                    return(NotFound());
                }
                var isvalid = _repo.Delete(vendor);
                if (!isvalid)
                {
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
Exemple #9
0
        public ActionResult Edit(VendorVm model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var vendor  = _mapper.Map <Vendor>(model);
                var isvalid = _repo.Update(vendor);

                if (!isvalid)
                {
                    ModelState.AddModelError("", "Could not edit vendors. Try Again");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Could not edit vendors. Try Again");
                return(View());
            }
        }
Exemple #10
0
        public ActionResult Create(VendorVm model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var vendor  = _mapper.Map <Vendor>(model);
                var isValid = _repo.Create(vendor);

                if (!isValid)
                {
                    ModelState.AddModelError("", "No Fields Affected");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "No Fields Affected");
                return(View(model));
            }
        }