public KeyValuePair <int, String> LetterEntry_ChangeStatus(LetterEntry model) { var param = new SqlParameter[] { new SqlParameter("@LetterEntryID", SqlDbType.UniqueIdentifier) { Value = model.LetterEntryID }, new SqlParameter("@ModifiedBy", SqlDbType.UniqueIdentifier) { Value = model.ModifiedBy }, new SqlParameter("@RetVal", SqlDbType.Int) { Direction = ParameterDirection.Output }, new SqlParameter("@Message", SqlDbType.VarChar, 200) { Direction = ParameterDirection.Output } }; List <string> listParams = new List <string>(); listParams.Add("@LetterEntryID"); listParams.Add("@ModifiedBy"); listParams.Add("@RetVal out"); listParams.Add("@Message out"); StringBuilder sBuilder = new StringBuilder(); sBuilder.Append("exec [CRM].[LetterEntry_ChangeStatus]"); sBuilder.Append(string.Join(",", listParams.ToArray())); int result = ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand(sBuilder.ToString(), param); int retVal = (int)param[listParams.Count - 2].Value; string message = (string)param[listParams.Count - 1].Value; return(new KeyValuePair <int, string>(retVal, message)); }
public ActionResult Edit(Guid Id) { LetterEntry le = db.letterEntry.Find(Id); Annotation annotation = db.annotation.Where(x => x.ObjectID == le.LetterEntryID).FirstOrDefault(); LetterEntryView model = new LetterEntryView(); model.Annotation = annotation; model.LetterEntry = le; List <SelectListItem> durations = new List <SelectListItem>(); for (int i = 0; i <= 5; i++) { string value = i.ToString(); string text = (i == 0) ? string.Empty : (i == 1) ? i + " day" : i + " days"; durations.Add(new SelectListItem { Text = text, Value = value }); } ViewData["ddl_durations"] = durations; ViewBag.Title = string.Format("Letter Entry: {0}", le.LetterNo); return(View(model)); }
public ActionResult Create(LetterEntryView model) { JSONResponse result = new JSONResponse(); result.Value = false; result.Response = string.Empty; try { if (Session["BusinessUnitID"] == null | Session["CurrentUserID"] == null) { throw new Exception(Resources.LetterEntry.Alert_SessionIsNull); } var businessunitid = new Guid(Convert.ToString(Session["BusinessUnitID"])); var systemuserid = new Guid(Convert.ToString(Session["CurrentUserID"])); var userid = db.systemUser.Single(p => p.SystemUserId == systemuserid); if (ModelState.IsValid) { StringBuilder errorMessages = new StringBuilder(), successMessages = new StringBuilder(); KeyValuePair <int, string> results = new KeyValuePair <int, string>(1, string.Empty); List <string> IdsList = string.IsNullOrEmpty(model.RequestIds) ? new List <string>() : new JavaScriptSerializer().Deserialize <List <string> >(model.RequestIds); if (IdsList.Count.Equals(0)) { throw new Exception(Resources.LetterEntry.Alert_NoRequest); } if (IdsList.Count > 5) { throw new Exception(Resources.LetterEntry.Alert_RequestMoreThanFive); } if (!model.LetterEntry.TemplateID.HasValue) { throw new Exception(Resources.LetterEntry.Alert_ChooseTemplate); } LetterTemplate lettertemplate = db.letterTemplate.Where(x => x.LetterTemplateId == model.LetterEntry.TemplateID).FirstOrDefault(); if (lettertemplate == null) { throw new Exception(Resources.LetterEntry.Alert_TemplateUndefined); } for (int i = 0; i <= IdsList.Count - 1; i++) { Guid requestId = new Guid(IdsList.ElementAt(i)); Request request = db.request.Where(x => x.RequestID == requestId).FirstOrDefault(); /* * Jika kondisi nya multiple-request, maka branch yang diambil adalah branch dari Request. * Sebaliknya, jika field CC diisi oleh user maka branch yang diambil adalah branch dari CC tersebut. * Sebaliknya, jika field UserBranch pada Request tidak null, maka branch yang diambil adalah branch dari Request. * Sebaliknya, branch sama dengan null. */ Guid branchID = (model.IsMultipleLetter) ? (request.BranchID.HasValue ? request.BranchID.Value : Guid.Empty) : (model.LetterEntry.CC_ID.HasValue ? model.LetterEntry.CC_ID.Value : (request.UserBranchID.HasValue ? request.UserBranchID.Value : Guid.Empty)); Branch branch = branchID.Equals(Guid.Empty) ? null : db.branch.Where(x => x.BranchID == branchID).FirstOrDefault(); string address1 = null, address2 = null, address3 = null, city = null, postalcode = null; if (request.Location != null) { StringMap stringmap = db.pickList .Where(x => x.EntityName.Equals("CustomerAddress") && x.AttributeName.Equals("addresstypecode") && x.AttributeValue.Equals(request.Location.Value)) .FirstOrDefault(); if (stringmap != null & stringmap.label.ToUpper().Equals("OTHER")) { address1 = request.Address1; address2 = request.Address2; city = request.City; postalcode = request.PostalCode; } else if (request.CustomerID != null) { CCARE.Models.Customer customer = db.customer.Where(x => x.CustomerID == request.CustomerID.Value).FirstOrDefault(); if (customer != null) { address1 = customer.Line1; address2 = customer.Line2; address3 = customer.Line3; city = customer.City; postalcode = customer.PostalCode; } } } else if (request.NonCustomerID != null) { NonCustomer noncustomer = db.noncustomer.Where(x => x.NonCustomerID == request.NonCustomerID.Value).FirstOrDefault(); if (noncustomer != null) { address1 = noncustomer.Address1; address2 = noncustomer.Address2; address3 = noncustomer.Address3; city = noncustomer.City; postalcode = noncustomer.Zipcode; } } LetterEntry letterentry = new LetterEntry(); letterentry.AccountNo = request.AccountNo; letterentry.Address1 = address1; letterentry.Address2 = address2; letterentry.Address3 = address3; letterentry.AttchATM = model.LetterEntry.AttchATM; letterentry.AttchATMSwitching = model.LetterEntry.AttchATMSwitching; letterentry.AttchCirrus = model.LetterEntry.AttchCirrus; letterentry.AttchDebit = model.LetterEntry.AttchDebit; letterentry.AttchMaestro = model.LetterEntry.AttchMaestro; letterentry.AttchDuration = model.LetterEntry.AttchDuration; letterentry.BusinessUnitID = businessunitid; letterentry.CardNo = request.CardNo; if (branch != null) { if (branch.BranchID != null) { letterentry.CC_ID = branch.BranchID; } if (!string.IsNullOrEmpty(branch.Name)) { letterentry.CC_Name = branch.Name; } } letterentry.City = city; letterentry.Description1 = model.LetterEntry.Description1; letterentry.Description2 = model.LetterEntry.Description2; letterentry.Description3 = model.LetterEntry.Description3; letterentry.Description4 = model.LetterEntry.Description4; letterentry.FullName = request.CustomerName; letterentry.LetterDate = model.LetterEntry.LetterDate == null ? DateTime.Now : model.LetterEntry.LetterDate.Value; letterentry.LetterEntryID = Guid.NewGuid(); if (lettertemplate.Type.Equals((int)LetterType.SPC)) { letterentry.LetterNo = Convert.ToString(Convert.ToDouble(model.LetterEntry.LetterNo) + i).PadLeft(4, '0'); } else { string bcaNo = db.AutoNumber_GetNext("Letter Entry", DateTime.Now.Year); if (bcaNo != "") { letterentry.LetterNo = string.Format("{0}/BHB/{1}/{2}", bcaNo.PadLeft(5, '0'), arrRomans.ElementAt(letterentry.LetterDate.Value.Month - 1), letterentry.LetterDate.Value.Year.ToString()); } else { errorMessages.AppendLine("Unable to generate letter entry. Auto Number record does not exist. "); continue; } } letterentry.ModifiedBy = systemuserid; letterentry.RequestID = request.RequestID.Value; letterentry.TicketNumber = request.TicketNumber; letterentry.TemplateID = lettertemplate.LetterTemplateId; letterentry.ZIPPostalCode = postalcode; results = db.LetterEntry_Insert(letterentry); if (results.Key == 0 || results.Key == 16 || results.Key == 6) { MergeDocument aMergeDocument = new MergeDocument(); JSONResponse mergeResult = aMergeDocument.Merge(letterentry.LetterEntryID); if (Convert.ToBoolean(mergeResult.Value)) { successMessages.Append(letterentry.LetterEntryID.ToString()); } else { errorMessages.AppendLine(string.Format(Resources.LetterEntry.Alert_GenerateLetterError, request.TicketNumber, mergeResult.Response)); } continue; } else { errorMessages.AppendLine(results.Value.ToString()); continue; } } string strAnyErrors = errorMessages.ToString(); string strAnySuccess = successMessages.ToString(); successMessages.AppendLine(strAnyErrors); if (string.IsNullOrEmpty(strAnyErrors)) { UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext); string url = u.Action("Edit", "LetterEntry", new { id = successMessages.ToString().Trim() }); result.Value = true; result.Response = url; } else { throw new Exception(successMessages.ToString()); } } else { foreach (var key in ModelState.Keys) { var error = ModelState[key].Errors.FirstOrDefault(); if (error != null) { throw new Exception(error.ErrorMessage); } } } } catch (Exception e) { result.Value = false; result.Response = e.Message; } return(Json(result)); }
public ActionResult SubmitForm(LetterEntry model, ActionType actionType) { List <string> errorMessage = new List <string>(); string successMessage = Resources.LetterEntry.Alert_Success; if (ModelState.IsValid) { KeyValuePair <int, string> results = new KeyValuePair <int, string>(1, string.Empty); if (Session["CurrentUserID"] == null) { var jsonData = new { flag = false, Message = Resources.LetterEntry.Alert_SessionIsNull }; return(Json(jsonData)); } model.ModifiedBy = new Guid(Convert.ToString(Session["CurrentUserID"])); switch (actionType) { case ActionType.Create: results = db.LetterEntry_Insert(model); break; case ActionType.Delete: results = db.LetterEntry_Delete(model); break; case ActionType.ChangeStatus: results = db.LetterEntry_ChangeStatus(model); break; default: break; } if (results.Key == 0 || results.Key == 16 || results.Key == 6) { UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext); string url = u.Action("Edit", "LetterEntry", new { id = model.LetterEntryID, success = successMessage }); string urlNew = u.Action("Create", "LetterEntry"); var jsonData = new { flag = true, Message = url, urlNew = urlNew }; return(Json(jsonData)); } else { var jsonData = new { flag = false, Message = results.Value.ToString() }; return(Json(jsonData)); } } else { foreach (var key in ModelState.Keys) { var error = ModelState[key].Errors.FirstOrDefault(); if (error != null) { errorMessage.Add(error.ErrorMessage); } } var jsonData = new { flag = false, Message = errorMessage.First() }; return(Json(jsonData)); } }
public KeyValuePair <int, String> LetterEntry_Insert(LetterEntry model) { var param = new SqlParameter[] { new SqlParameter("@LetterEntryID", SqlDbType.UniqueIdentifier) { Value = model.LetterEntryID }, new SqlParameter("@RequestID", SqlDbType.UniqueIdentifier) { Value = model.RequestID }, new SqlParameter("@TicketNumber", SqlDbType.VarChar, 200) { Value = CheckForDbNull(model.TicketNumber) }, new SqlParameter("@TemplateID", SqlDbType.UniqueIdentifier) { Value = CheckForDbNull(model.TemplateID) }, new SqlParameter("@LetterDate", SqlDbType.DateTime) { Value = CheckForDbNull(model.LetterDate) }, new SqlParameter("@LetterNo", SqlDbType.VarChar, 200) { Value = CheckForDbNull(model.LetterNo) }, new SqlParameter("@CC_ID", SqlDbType.UniqueIdentifier) { Value = CheckForDbNull(model.CC_ID) }, new SqlParameter("@AttchATM", SqlDbType.Bit) { Value = CheckForDbNull(model.AttchATM) }, new SqlParameter("@AttchDebit", SqlDbType.Bit) { Value = CheckForDbNull(model.AttchDebit) }, new SqlParameter("@AttchCirrus", SqlDbType.Bit) { Value = CheckForDbNull(model.AttchCirrus) }, new SqlParameter("@AttchATMSwitching", SqlDbType.Bit) { Value = CheckForDbNull(model.AttchATMSwitching) }, new SqlParameter("@AttchMaestro", SqlDbType.Bit) { Value = CheckForDbNull(model.AttchMaestro) }, new SqlParameter("@AttchDuration", SqlDbType.Int) { Value = CheckForDbNull(model.AttchDuration) }, new SqlParameter("@Description1", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Description1) }, new SqlParameter("@Description2", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Description2) }, new SqlParameter("@Description3", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Description3) }, new SqlParameter("@Description4", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Description4) }, new SqlParameter("@FullName", SqlDbType.VarChar, 200) { Value = CheckForDbNull(model.FullName) }, new SqlParameter("@AccountNo", SqlDbType.VarChar, 200) { Value = CheckForDbNull(model.AccountNo) }, new SqlParameter("@CardNo", SqlDbType.VarChar, 200) { Value = CheckForDbNull(model.CardNo) }, new SqlParameter("@Address1", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Address1) }, new SqlParameter("@Address2", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Address2) }, new SqlParameter("@Address3", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.Address3) }, new SqlParameter("@City", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.City) }, new SqlParameter("@ZipPostalCode", SqlDbType.VarChar, 100) { Value = CheckForDbNull(model.ZIPPostalCode) }, new SqlParameter("@ModifiedBy", SqlDbType.UniqueIdentifier) { Value = CheckForDbNull(model.ModifiedBy) }, new SqlParameter("@BusinessUnitID", SqlDbType.UniqueIdentifier) { Value = CheckForDbNull(model.BusinessUnitID) }, new SqlParameter("@RetVal", SqlDbType.Int) { Direction = ParameterDirection.Output }, new SqlParameter("@Message", SqlDbType.VarChar, 200) { Direction = ParameterDirection.Output } }; List <string> listParams = new List <string>(); listParams.Add("@LetterEntryID"); listParams.Add("@RequestID"); listParams.Add("@TicketNumber"); listParams.Add("@TemplateID"); listParams.Add("@LetterDate"); listParams.Add("@LetterNo"); listParams.Add("@CC_ID"); listParams.Add("@AttchATM"); listParams.Add("@AttchDebit"); listParams.Add("@AttchCirrus"); listParams.Add("@AttchATMSwitching"); listParams.Add("@AttchMaestro"); listParams.Add("@AttchDuration"); listParams.Add("@Description1"); listParams.Add("@Description2"); listParams.Add("@Description3"); listParams.Add("@Description4"); listParams.Add("@FullName"); listParams.Add("@AccountNo"); listParams.Add("@CardNo"); listParams.Add("@Address1"); listParams.Add("@Address2"); listParams.Add("@Address3"); listParams.Add("@City"); listParams.Add("@ZipPostalCode"); listParams.Add("@ModifiedBy"); listParams.Add("@BusinessUnitID"); listParams.Add("@RetVal out"); listParams.Add("@Message out"); StringBuilder sBuilder = new StringBuilder(); sBuilder.Append("exec [CRM].[LetterEntry_Insert]"); sBuilder.Append(string.Join(",", listParams.ToArray())); int result = ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand(sBuilder.ToString(), param); int retVal = (int)param[listParams.Count - 2].Value; string message = (string)param[listParams.Count - 1].Value; return(new KeyValuePair <int, string>(retVal, message)); }