public IHttpActionResult PutDuck(DuckViewModel duck) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new SklepEntities()) { var ExistingDuck = ctx.Kaczki.Where(I => I.Kaczka_id == duck.DuckId).FirstOrDefault(); if (ExistingDuck != null) { ExistingDuck.Rodzaj = duck.DuckType; ExistingDuck.Cena = duck.DuckPrice; ExistingDuck.Kraj_id = duck.DuckCountryId; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public DuckView() { InitializeComponent(); var vm = new DuckViewModel(); vm.Navigation = this.Navigation; BindingContext = vm; }
public ActionResult EditDuck(int id) { var ducks = unitOfWork.DuckRepository.GetByID(id); var config = new MapperConfiguration(cfg => cfg.AddProfile(new MapperProfile())); var mapper = config.CreateMapper(); Duck = mapper.Map <DuckViewModel>(ducks); PopulateList(); return(View(Duck)); }
public IHttpActionResult PostNewDuck(DuckViewModel duck) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new SklepEntities()) { ctx.Kaczki.Add(new Kaczki() { Kaczka_id = NextDuckIndex, Rodzaj = duck.DuckType, Cena = duck.DuckPrice, Kraj_id = duck.DuckCountryId }); ctx.SaveChanges(); } return(Ok()); }
public ActionResult CreateDuck(DuckViewModel duck) { PopulateList(); var config = new MapperConfiguration(cfg => cfg.AddProfile(new MapperProfile())); var mapper = config.CreateMapper(); try { if (ModelState.IsValid) { unitOfWork.DuckRepository.Insert(mapper.Map <Kaczki>(duck)); unitOfWork.Save(); return(RedirectToAction("DuckIndex")); //TODO:logger } } } catch (DataException) { } ModelState.AddModelError(string.Empty, "Cannot create duck"); return(View(Duck)); }
public ActionResult EditDuck(DuckViewModel duck) { PopulateList(); duck.CountryList = Duck.CountryList; var config = new MapperConfiguration(cfg => cfg.AddProfile(new MapperProfile())); var mapper = config.CreateMapper(); try { if (ModelState.IsValid) { unitOfWork.DuckRepository.Update(mapper.Map <Kaczki>(duck)); unitOfWork.Save(); //TODO: logger return(RedirectToAction("DuckIndex")); } } catch (DataException) { } PopulateList(); return(View(duck)); }