private async Task <bool> UnitVMExists(int id) { if (id == 0) { return(false); } UnitVM unitVM = new UnitVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/Units/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; unitVM = JsonConvert.DeserializeObject <UnitVM>(result); } if (unitVM == null) { return(false); } return(true); //return _context.UnitVM.Any(e => e.UnitId == id); }
public ActionResult Edit(UnitVM poViewModel) { ViewBag.AC_MENU_ID = valMENU.MST_UNIT_EDIT; this.oVAL = new Unit_Validation(poViewModel, this.oDS); this.oVAL.Validate_Edit(); //Add Error if exists for (int i = 0; i < this.oVAL.aValidationMSG.Count; i++) { ModelState.AddModelError(this.oVAL.aValidationMSG[i].VAL_ERRID, this.oVAL.aValidationMSG[i].VAL_ERRMSG); } //End for (int i = 0; i < this.oVAL.aValidationMSG.Count; i++) if (ModelState.IsValid) { this.oCRUD.Update(poViewModel); this.oCRUD.Commit(); if (this.oCRUD.isERR) { TempData["ERRMSG"] = this.oCRUD.ERRMSG; return(RedirectToAction("ErrorSYS", "Error")); } //End if (!this.oCRUD.isERR) { TempData["CRUDSavedOrDelete"] = valFLAG.FLAG_TRUE; return(RedirectToAction("Details", new { id = this.oCRUD.ID })); } return(View(poViewModel)); }
public ActionResult Edit(int? id = null) { ViewBag.AC_MENU_ID = valMENU.MST_UNIT_EDIT; ViewBag.CRUD_type = hlpFlags_CRUDOption.UPDATE; this.oData = oDS.getData(id); if (this.oData == null) { return HttpNotFound(); } return View(this.oData); }
public UnitVM Get(int ID) { var Unit = db.Units.Find(ID); UnitVM UnitVM = new UnitVM(); UnitVM.ID = Unit.ID; UnitVM.Name = Unit.Name; return(UnitVM); }
public ActionResult Details(int? id = null) { ViewBag.AC_MENU_ID = valMENU.MST_UNIT_DETAILS; ViewBag.CRUD_type = hlpFlags_CRUDOption.VIEW; ViewBag.CRUDSavedOrDelete = TempData["CRUDSavedOrDelete"]; this.oData = oDS.getData(id); if (this.oData == null) { return HttpNotFound(); } return View(this.oData); }
public ActionResult Delete(int? id = null) { //Hardcode return RedirectToAction("Details", new { id = 1 }); //ViewBag.AC_MENU_ID = valMENU.MODULE_DELETE; ViewBag.CRUD_type = hlpFlags_CRUDOption.DELETE; this.oData = oDS.getData(id); if (this.oData == null) { return HttpNotFound(); } return View(this.oData); }
public JsonResult Save(UnitVM UnitVM) { if (ModelState.IsValid) { var check = UnitVM.ID > 0 ? service.Edit(UnitVM) : service.Save(UnitVM); return(Json(new { status = check }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult SaveUnit(UnitVM UnitMaster) { List <SessionListnew> list = Session["SesDet"] as List <SessionListnew>; if (list == null) { return(Redirect("Login/InLogin")); } else { return(Json(_materialService.SaveUnit(list[0].CmpyCode, UnitMaster), JsonRequestBehavior.AllowGet)); } }
//BL //MAP //Init private void initConstructor(DBMAINContext poDB) { //DBContext this.db = poDB; //VM this.oVM = new UnitVM(); //DS this.oDS = new UnitDS(this.db); //CRUD this.oCRUD = new UnitCRUD(this.db); //BL //MAP } //End initConstructor
public bool Edit(UnitVM UnitVM) { try { Unit Unit = db.Units.Find(UnitVM.ID); Unit.Name = UnitVM.Name; db.Entry(Unit).State = EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } }
public bool Save(UnitVM UnitVM) { try { Unit Unit = new Unit(); Unit.Name = UnitVM.Name; db.Units.Add(Unit); db.SaveChanges(); return(true); } catch { return(false); } }
// GET: Unit/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } UnitVM unitVM = new UnitVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/Units/" + id); if (res.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list unitVM = JsonConvert.DeserializeObject <UnitVM>(result); } if (unitVM == null) { return(NotFound()); } return(View(unitVM)); //if (id == null) //{ // return NotFound(); //} //var unitVM = await _context.UnitVM // .FirstOrDefaultAsync(m => m.UnitId == id); //if (unitVM == null) //{ // return NotFound(); //} //return View(unitVM); }
public IActionResult Upsert(int?id) { UnitVM unitVM; unitVM = new UnitVM(); unitVM.CategoryList = _unitOfWork.Category.GetCategoryListForDropDown(); if (id == null) { unitVM.Unit = new Unit(); } else { unitVM.Unit = _unitOfWork.Unit.Get(id.GetValueOrDefault()); if (unitVM.Unit == null) { return(NotFound()); } } return(View(unitVM)); }
public IActionResult Upsert(UnitVM unitVM) { if (ModelState.IsValid) { if (unitVM.Unit.Id == 0) { _unitOfWork.Unit.Add(unitVM.Unit); } else { _unitOfWork.Unit.Update(unitVM.Unit); } _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } else { unitVM.CategoryList = _unitOfWork.Category.GetCategoryListForDropDown(); return(View(unitVM)); } }
// GET: Unit/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } UnitVM unitVM = new UnitVM(); HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res = await client.GetAsync("api/Units/" + id); if (res.IsSuccessStatusCode) { var result = res.Content.ReadAsStringAsync().Result; unitVM = JsonConvert.DeserializeObject <UnitVM>(result); } if (unitVM == null) { return(NotFound()); } return(View(unitVM)); //if (id == null) //{ // return NotFound(); //} //var unitVM = await _context.UnitVM // .FirstOrDefaultAsync(m => m.UnitId == id); //if (unitVM == null) //{ // return NotFound(); //} //return View(unitVM); }
public async Task <IActionResult> Create([Bind("UnitId,UnitName,UnitSymbol,Description,IsActive,DateAdded,DateUpdated")] UnitVM unitVM) { if (ModelState.IsValid) { HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); var content = new StringContent(JsonConvert.SerializeObject(unitVM), Encoding.UTF8, "application/json"); //Task has been cancelled exception occured here, and Api method never hits while debugging HttpResponseMessage res = client.PostAsync("api/Units", content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(unitVM)); //if (ModelState.IsValid) //{ // _context.Add(unitVM); // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); //} //return View(unitVM); }
public UnitVM SaveUnit(string cmpyCode, UnitVM unit) { return(_materialRepo.SaveUnit(cmpyCode, unit)); }
void SetUpButton(UnitVM unit) { unit.IsPressable = true; }
public UnitVM SaveUnit(string cmpyCode, UnitVM unit) { try { if (!unit.EditFlag) { var Drecord = new List <string>(); List <UnitNew> ObjList = new List <UnitNew>(); ObjList.AddRange(unit.UnitNew.Select(m => new UnitNew { Code = m.Code, CmpyCode = m.CmpyCode, Name = m.Name, UnitType = m.UnitType, UniCodeName = m.UniCodeName }).ToList()); int n = 0; n = ObjList.Count; while (n > 0) { int unit1 = _EzBusinessHelper.ExecuteScalar("Select count(*) from MMU001 where CmpyCode='" + cmpyCode + "' and Code='" + ObjList[n - 1].Code + "'"); if (unit1 == 0) { StringBuilder sb = new StringBuilder(); sb.Append("'" + cmpyCode + "',"); sb.Append("'" + ObjList[n - 1].Code + "',"); sb.Append("'" + ObjList[n - 1].UnitType + "',"); sb.Append("'" + ObjList[n - 1].Name + "')"); // sb.Append("'" + ObjList[n - 1].Act_code + "')"); _EzBusinessHelper.ExecuteNonQuery("insert into MMU001(CmpyCode,Code,UnitType,Name)values(" + sb.ToString() + ""); unit.SaveFlag = true; unit.ErrorMessage = string.Empty; } else { Drecord.Add(ObjList[n - 1].Code.ToString()); unit.Drecord = Drecord; unit.SaveFlag = false; unit.ErrorMessage = "Duplicate Record"; } n = n - 1; } return(unit); } var unitEdit = _EzBusinessHelper.ExecuteScalar("Select * from MMU001 where CmpyCode='" + unit.CmpyCode + "' and Code='" + unit.Code + "'"); if (unitEdit != 0) { _EzBusinessHelper.ExecuteNonQuery("update MMU001 set CmpyCode='" + unit.CmpyCode + "',Code='" + unit.Code + "',Name='" + unit.Name + "',UniCodeName='" + unit.UniCodeName + "',UnitType='" + unit.UnitType + "' where CmpyCode='" + unit.CmpyCode + "' and Code='" + unit.Code + "'"); unit.SaveFlag = true; unit.ErrorMessage = string.Empty; } else { unit.SaveFlag = false; unit.ErrorMessage = "Record not available"; } } catch (Exception ex) { unit.SaveFlag = false; // unit.ErrorMessage = exceptionMessage; } return(unit); }
public UnitView(UnitVM vm) { InitializeComponent(); ViewModel = vm; }
public async Task <IActionResult> Edit(int id, [Bind("UnitId,UnitName,UnitSymbol,Description,IsActive,DateAdded,DateUpdated")] UnitVM unitVM) { if (id != unitVM.UnitId) { return(NotFound()); } if (ModelState.IsValid) { try { HttpClient client = _helperAPI.InitializeClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); var content = new StringContent(JsonConvert.SerializeObject(unitVM), Encoding.UTF8, "application/json"); HttpResponseMessage res = client.PutAsync("api/Units/" + id, content).Result; if (res.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException) { //if (!RoleVMExists(roleVM.Id)) //{ // return NotFound(); //} //else //{ throw; //} } return(RedirectToAction(nameof(Index))); } return(View(unitVM)); //if (id != unitVM.UnitId) //{ // return NotFound(); //} //if (ModelState.IsValid) //{ // try // { // _context.Update(unitVM); // await _context.SaveChangesAsync(); // } // catch (DbUpdateConcurrencyException) // { // if (!UnitVMExists(unitVM.UnitId)) // { // return NotFound(); // } // else // { // throw; // } // } // return RedirectToAction(nameof(Index)); //} //return View(unitVM); }
// GET: SaleContract/Details/5 public async Task <IActionResult> Details(long?id) { if (id == null) { return(NotFound()); } SaleContractVM saleContractVM = new SaleContractVM(); HttpClient client = _helperAPI.InitializeClient(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TempData.Peek("Token").ToString()); HttpResponseMessage res = await client.GetAsync("api/SaleContracts/" + id); if (res.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list saleContractVM = JsonConvert.DeserializeObject <SaleContractVM>(result); } if (saleContractVM == null) { return(NotFound()); } #region Get Sale Contract Items List <SaleContractItemVM> saleContractItemVM = new List <SaleContractItemVM>(); var contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res1 = await client.GetAsync("api/SaleContractItems/GetSaleContractItemBySaleContractId/" + id); if (res1.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res1.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res1.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the role list saleContractItemVM = JsonConvert.DeserializeObject <List <SaleContractItemVM> >(result); foreach (var item in saleContractItemVM) { #region Unit UnitVM unitVM = new UnitVM(); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage resUnit = await client.GetAsync("api/Units/" + item.UnitId); if (resUnit.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (resUnit.IsSuccessStatusCode) { //Storing the response details recieved from web api var resultUnit = resUnit.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list unitVM = JsonConvert.DeserializeObject <UnitVM>(resultUnit); item.Unit = unitVM; } if (unitVM == null) { return(NotFound()); } #endregion } } //returning the role list to view #endregion saleContractVM.SaleContractItems = saleContractItemVM; #region Customer Information CustomerVM customerVM = new CustomerVM(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); HttpResponseMessage res2 = await client.GetAsync("api/Customers/" + saleContractVM.CustomerId); if (res2.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (res2.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res2.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list customerVM = JsonConvert.DeserializeObject <CustomerVM>(result); } if (customerVM == null) { return(NotFound()); } saleContractVM.Customer = customerVM; #endregion #region Currency CurrencyVM currencyVM = new CurrencyVM(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage currencyVMRes = await client.GetAsync("api/Currencies/" + saleContractVM.CurrencyId); if (currencyVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (currencyVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = currencyVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list currencyVM = JsonConvert.DeserializeObject <CurrencyVM>(result); } if (currencyVM == null) { return(NotFound()); } saleContractVM.Currency = currencyVM; #endregion #region Bank Details BankInfoVM bankInfoVM = new BankInfoVM(); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("token")); //var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json"); HttpResponseMessage bankInfoVMRes = await client.GetAsync("api/BankInfo/" + saleContractVM.BankDetails); if (bankInfoVMRes.StatusCode == HttpStatusCode.Unauthorized) { ViewBag.Message = "Unauthorized!"; } //Checking the response is successful or not which is sent using HttpClient if (bankInfoVMRes.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = bankInfoVMRes.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Role list bankInfoVM = JsonConvert.DeserializeObject <BankInfoVM>(result); saleContractVM.BankDetailsNavigation = bankInfoVM; } #endregion Bank Details return(View(saleContractVM)); //if (id == null) //{ // return NotFound(); //} //var saleContractVM = await _context.SaleContractVM // .Include(s => s.Currency) // .Include(s => s.Customer) // .FirstOrDefaultAsync(m => m.SaleContractId == id); //if (saleContractVM == null) //{ // return NotFound(); //} //return View(saleContractVM); }