public bool CreateOrEdit(ReceiptDetailDTO model, string useid, ref string msg) { try { AddOrRemoveDeviceSerialNoRequest paraBody = new AddOrRemoveDeviceSerialNoRequest(); //paraBody.Currency = model; paraBody.CreatedUser = useid; paraBody.ListSerialNo = model.ListSerialNo; var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CustomerAssetAddserialnumber, null, paraBody); if (result != null) { if (result.Success) { return(true); } else { msg = result.Message; //msg = Commons.ErrorMsg; NSLog.Logger.Info("OrderReceiptManagement_CreateOrEdit", result.Message); return(false); } } else { NSLog.Logger.Info("OrderReceiptManagement_CreateOrEdit", result); return(false); } } catch (Exception e) { NSLog.Logger.Error("OrderReceiptManagement_CreateOrEdit_Fail", e); return(false); } }
public ReceiptDetailDTO GetDetail(string ID) { ReceiptDetailDTO model = new ReceiptDetailDTO(); try { GetReceiptDetailRequest paraBody = new GetReceiptDetailRequest(); paraBody.ID = ID; var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CustomerReceiptGetDetail, null, paraBody); dynamic data = result.Data; var lstDataRaw = data["ReceiptDetail"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); model = JsonConvert.DeserializeObject <ReceiptDetailDTO>(lstObject); if (model != null) { model.Date = CommonHelper.ConvertToLocalTime(model.Date); } NSLog.Logger.Info("OrderReceiptManagement_GetDetail", model); return(model); } catch (Exception e) { NSLog.Logger.Error("OrderReceiptManagement_GetDetail_Fail", e); return(model); } }
public ActionResult Create(ReceiptDetailDTO model) { try { //============================= string msg = ""; bool result = _factory.CreateOrEdit(model, CurrentUser.UserId, ref msg); if (result) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("OrderReceiptManagement_Create: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ReceiptDetailDTO GetDetail(string id) { try { ReceiptDetailDTO model = _factory.GetDetail(id); if (model.ListAdditionItem != null && model.ListAdditionItem.Count > 0) { int count = 0; foreach (var item in model.ListAdditionItem) { switch (item.AdditionType) { case (byte)Commons.EAdditionType.Hardware: item.AdditionName = @Commons.EAdditionType.Hardware.ToString(); if (item.State == (byte)Commons.EServiceAssetStatus.New) { item.SerialNoView = "Updating"; } else { item.SerialNoView = item.SerialNo; } break; //case (byte)Commons.EAdditionType.Software: // item.AdditionName = @Commons.EAdditionType.Software.ToString(); // break; case (byte)Commons.EAdditionType.Service: item.AdditionName = @Commons.EAdditionType.Service.ToString(); break; } //if (string.IsNullOrEmpty(item.SerialNo) && item.State == (byte)Commons.EServiceAssetStatus.New && item.AdditionType == (byte)Commons.EAdditionType.Hardware) //{ // item.SerialNoView = "Updating"; //} //else //{ // item.SerialNoView = item.SerialNo; //} item.StateChange = item.State; switch (item.State) { case (byte)Commons.EServiceAssetStatus.New: item.StatusName = @Commons.EServiceAssetStatus.New.ToString(); break; case (byte)Commons.EServiceAssetStatus.Done: item.StatusName = @Commons.EServiceAssetStatus.Done.ToString(); break; case (byte)Commons.EServiceAssetStatus.Recalled: item.StatusName = @Commons.EServiceAssetStatus.Recalled.ToString(); break; } item.Offset = count; count++; } } return(model); } catch (Exception ex) { NSLog.Logger.Error("OrderReceiptManagementDetail: ", ex); return(null); } }
public ActionResult Edit(ReceiptDetailDTO model) { try { //if (model.ListAdditionItem != null && model.ListAdditionItem.Count > 0) //{ // var count1 = model.ListAdditionItem.Where(o => o.Update == 9 && o.AdditionType != (byte)Commons.EAdditionType.Service).Select(s =>s.SerialNo).ToList().Count(); // var count2 = model.ListAdditionItem.Where(o => o.Update == 9 && o.AdditionType != (byte)Commons.EAdditionType.Service).Select(s => s.SerialNo).Distinct().ToList().Count(); // if (count1 != count2) // { // ModelState.AddModelError("errorItem", "Serial number cannot be duplicated."); // } //} //==================== List <SerialNumberDTO> ListSerialNo = new List <SerialNumberDTO>(); var lstSerialNo = model.ListAdditionItem.Where(o => o.Update == 9).ToList(); if (lstSerialNo != null && !lstSerialNo.Any()) { ModelState.AddModelError("errorItem", "Nothing has changed. Please try again."); } if (!ModelState.IsValid) { model = GetDetail(model.ID); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } lstSerialNo.ForEach(xx => { if (!string.IsNullOrEmpty(xx.SerialNo)) { xx.SerialNo = RemoveSpecChar(xx.SerialNo); } ListSerialNo.Add(new SerialNumberDTO { AssetID = xx.AssetID, SerialNo = xx.SerialNo, State = xx.StateChange }); }); //lstSerialNo = model.ListAdditionItem.Where(o => o.Update == 9).Select(s => new SerialNumberDTO //{ // AssetID = s.AssetID, // // Remove white spaces // SerialNo = s.SerialNo, // State = s.StateChange //}).ToList(); //if (lstSerialNo != null && lstSerialNo.Count > 0) //{ // foreach (var item in lstSerialNo) // { // if (item.State == (byte)Commons.EServiceAssetStatus.Recalled) // { // //item.SerialNo = ""; // } // } //} model.ListSerialNo = ListSerialNo; string msg = ""; var result = _factory.CreateOrEdit(model, CurrentUser.UserId, ref msg); if (result) { return(RedirectToAction("Index")); } else { model = GetDetail(model.ID); lstSerialNo.ForEach( xy => { var itemChanged = model.ListAdditionItem.Where(w => w.AssetID == xy.AssetID).FirstOrDefault(); if (itemChanged != null) { itemChanged.SerialNo = xy.SerialNo; itemChanged.SerialNoView = xy.SerialNo; itemChanged.State = xy.StateChange; itemChanged.StateChange = xy.StateChange; itemChanged.StatusName = xy.StatusName; itemChanged.Update = xy.Update; } } ); ModelState.AddModelError("errorItem", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { NSLog.Logger.Error("OrderReceiptManagement_Edit: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public PartialViewResult Edit(string id) { ReceiptDetailDTO model = GetDetail(id); return(PartialView("_Edit", model)); }
public ActionResult Create() { ReceiptDetailDTO model = new ReceiptDetailDTO(); return(View(model)); }
public new PartialViewResult View(string id) { ReceiptDetailDTO model = GetDetail(id); return(PartialView("_View", model)); }