public ActionResult AddEditFabric(FabricViewModel model) { if (ModelState.IsValid) { var result = ""; if (model.Id > 0) { var url = "/fabrics/" + model.Id; var jsonObj = new JavaScriptSerializer().Serialize(model); result = Common.Put(url, model); } else { var url = "/fabrics"; result = Common.Post(url, model); } if (result != null || result != "Invalid Fabric") { return(RedirectToAction("Confirmation", "Home")); //return RedirectToMainPage(); } } return(View()); }
// GET: Fabrics/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Fabric fabric = db.Frabrics.Find(id); if (fabric == null) { return(HttpNotFound()); } var Results = from b in db.FabricRestrictions select new { b.Id, b.Name, Checked = ((from ab in db.Fabric_Restrictions where (ab.FabricId == id) && (ab.FabricRestrictionId == b.Id) select ab).Count() > 0) }; var MyViewModel = new FabricViewModel(); MyViewModel.FabricId = id.Value; MyViewModel.Name = fabric.Name; MyViewModel.ImageUrl = fabric.ImageUrl; MyViewModel.FabricBookId = fabric.FabricBookId; FabricBook fb = db.FabricBooks.Find(MyViewModel.FabricBookId); if (fb == null) { return(HttpNotFound()); } else { MyViewModel.FabricBooks = new FabricBook() { Id = fb.Id, Name = fb.Name }; } var MyCheckBoxList = new List <CheckBoxViewModel>(); foreach (var item in Results) { MyCheckBoxList.Add(new CheckBoxViewModel { Id = item.Id, Name = item.Name, Checked = item.Checked }); } MyViewModel.Restrictions = MyCheckBoxList; ViewBag.FabricBookId = new SelectList(db.FabricBooks, "Id", "Name", fabric.FabricBookId); return(View(MyViewModel)); }
//get selected fabric details by id private FabricViewModel GetFabricById(int id) { FabricViewModel model = null; var url = "/fabrics/" + id; var result = Common.Get(url); model = JsonConvert.DeserializeObject <FabricViewModel>(result); return(model); }
public async Task <Uri> AddFabricAsync(FabricViewModel fabric) { string obj = JsonConvert.SerializeObject(fabric); var content = new StringContent(obj, Encoding.UTF8, "application/json"); var res = await _client.PostAsync(_client.BaseAddress, content); Console.WriteLine(res.ToString()); res.EnsureSuccessStatusCode(); return(res.Headers.Location); }
public async Task <FabricViewModel> UpdateFabric(FabricViewModel fabric) { string obj = JsonConvert.SerializeObject(fabric); var content = new StringContent(obj, Encoding.UTF8, "application/json"); var res = await _client.PutAsJsonAsync(string.Format($@"{_client.BaseAddress}/{fabric.id}"), content); res.EnsureSuccessStatusCode(); var updatedfabric = await res.Content.ReadAsAsync <FabricViewModel>(); return(updatedfabric); }
public async Task <FabricViewModel> GetFabricAsync(int id) { FabricViewModel _fabric = null; Task <HttpResponseMessage> t = _client.GetAsync(string.Format($@"{_client.BaseAddress}/{id}")); var res = t.Result; if (res.IsSuccessStatusCode) { _fabric = await res.Content.ReadAsAsync <FabricViewModel>(); } return(_fabric); }
public IActionResult UpdateFabric(FabricViewModel fabric) { try { var res = api.UpdateFabric(fabric); var fb = res.Result; return(View("FabricDetail", fb)); } catch (Exception ex) { var err = new ErrorViewModel(); err.ErrorMessage = ex.Message; err.TargetSite = ex.TargetSite.ToString(); err.Trace = ex.StackTrace.ToString(); return(View("Error", err)); } }
public ActionResult Edit(FabricViewModel fabric, HttpPostedFileBase img) { if (ModelState.IsValid) { var myFabric = db.Frabrics.Find(fabric.FabricId); if (img != null) { var folder = Server.MapPath("~/Content/Fabrics/"); var imageUrl = Path.GetFileName(img.FileName); var filename = Path.Combine(folder, imageUrl); img.SaveAs(filename); myFabric.ImageUrl = imageUrl; } myFabric.Name = fabric.Name; myFabric.FabricBookId = fabric.FabricBookId; foreach (var item in db.Fabric_Restrictions) { if (item.FabricId == fabric.FabricId) { db.Entry(item).State = EntityState.Deleted; } } foreach (var item in fabric.Restrictions) { if (item.Checked) { db.Fabric_Restrictions.Add(new Fabric_Restriction() { FabricId = fabric.FabricId, FabricRestrictionId = item.Id }); } } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FabricBookId = new SelectList(db.FabricBooks, "Id", "Name", fabric.FabricBookId); return(View(fabric)); }
public IActionResult Edit(FabricViewModel fabric) { return(View(fabric)); }
public IActionResult AddNew() { var vm = new FabricViewModel(); return(View(vm)); }