public async Task <JsonResult> SaveAppraisedItem(tbl_ipos_appraiseditem item) { try { tbl_ipos_appraiseditem model = null; bool success = false; string message = ""; if (string.IsNullOrEmpty(item.AppraiseId.ToString()) || item.AppraiseId.ToString() == "0") { //DateTime dt = DateTime.ParseExact(item.AppraiseDate, "yyyy/MM/dd", CultureInfo.InvariantCulture); model = new tbl_ipos_appraiseditem(); model.AppraiseDate = item.AppraiseDate; model.AppraiseNo = item.AppraiseNo; model.ItemTypeId = item.ItemTypeId; model.ItemCategoryId = item.ItemCategoryId; model.ItemName = item.ItemName; model.Brand = item.Brand; model.Karat = item.Karat; model.Weight = item.Weight; model.AppraisedValue = item.AppraisedValue; model.Remarks = item.Remarks; model.CustomerFirstName = item.CustomerFirstName; model.CustomerLastName = item.CustomerLastName; model.IsPawned = false; model.CreatedAt = DateTime.Now; model.CreatedBy = ""; var result = await _appraisalService.Save(model); success = result; if (result) { tbl_ipos_pawnshop_transactions model1 = await _pawnshopTransactionService.FindByIdPawnshopTransactions(item.AppraiseId); model1.Status = "For pawning"; await _pawnshopTransactionService.UpdatePawnshopTransactions(model1); message = "Successfully saved."; } else { message = "Error saving data. Duplicate entry."; } } else { model = await _appraisalService.FindById(item.AppraiseId); model.ItemTypeId = item.ItemTypeId; model.ItemCategoryId = item.ItemCategoryId; model.ItemName = item.ItemName; model.Brand = item.Brand; model.Karat = item.Karat; model.Weight = item.Weight; model.AppraisedValue = item.AppraisedValue; model.Remarks = item.Remarks; model.CustomerFirstName = item.CustomerFirstName; model.CustomerLastName = item.CustomerLastName; model.IsPawned = false; model.CreatedAt = DateTime.Now; model.CreatedBy = ""; var result = await _appraisalService.Update(model); success = result; if (result) { tbl_ipos_pawnshop_transactions model1 = await _pawnshopTransactionService.FindByIdPawnshopTransactions(item.AppraiseId); model1.Status = "For pawning"; await _pawnshopTransactionService.UpdatePawnshopTransactions(model1); message = "Successfully updated."; } else { message = "Error saving data. Please contact administrator."; } } return(Json(new { success = success, message = message })); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <JsonResult> SaveAppraisal(tbl_ipos_appraiseditem model) { try { bool success = false; string message = ""; if (string.IsNullOrEmpty(model.AppraiseId.ToString()) || model.AppraiseId.ToString() == "0") { tbl_ipos_appraiseditem model1 = new tbl_ipos_appraiseditem(); model1.AppraiseDate = model.AppraiseDate; //model1.AppraiseNo = ""; //model1.ItemTypeId = model.ItemTypeId; //model1.ItemCategoryId = model.ItemCategoryId; //model1.ItemName = model.ItemName; model1.ItemFeature = model.ItemFeature; model1.SerialNo = model.SerialNo; model1.ItemCondition = model.ItemCondition; model1.Weight = model.Weight; model1.AppraisedValue = model.AppraisedValue; //model1.Remarks = model.Remarks; //model1.CustomerFirstName = model.first_name; //model1.CustomerLastName = model.last_name; //model1.IsPawned = false; //model1.CreatedAt = DateTime.Now; //model1.CreatedBy = ""; //model1.PawnshopTransactionId = model.TransactionNo.ToString(); var result = await _appraisalService.Save(model1); success = result; if (result) { message = "Successfully saved."; } else { message = "Error saving data. Duplicate entry."; } } else { tbl_ipos_appraiseditem model1 = new tbl_ipos_appraiseditem(); model1 = await _appraisalService.FindByTransactionNo(model.PawnshopTransactionId); model1.AppraiseDate = model.AppraiseDate; //model1.AppraiseNo = ""; //model1.ItemTypeId = model.ItemTypeId; //model1.ItemCategoryId = model.ItemCategoryId; //model1.ItemName = model.ItemName; model1.ItemFeature = model.ItemFeature; model1.SerialNo = model.SerialNo; model1.ItemCondition = model.ItemCondition; model1.Karat = model.Karat; model1.Weight = model.Weight; model1.AppraisedValue = model.AppraisedValue; //model1.Remarks = model.Remarks; //model1.CustomerFirstName = model.first_name; //model1.CustomerLastName = model.last_name; //model1.IsPawned = false; //model1.CreatedAt = DateTime.Now; //model1.CreatedBy = ""; //model1.PawnshopTransactionId = model.TransactionNo.ToString(); var result = await _appraisalService.Update(model1); success = result; if (result) { tbl_ipos_pawnshop_transactions model2 = await _pawnshopTransactionService.FindByTransactionNo(model.PawnshopTransactionId); model2.Status = "For pawning"; await _pawnshopTransactionService.UpdatePawnshopTransactions(model2); message = "Successfully updated."; } else { message = "Error saving data. Please contact administrator."; } } return(Json(new { success = success, message = message })); } catch (Exception ex) { throw new Exception(ex.Message); } }