public ActionResult AddOrEdit(_Distributor distributor) { if (distributor.DistributorId == 0) { if (distributorService.Add(distributor)) { return(Json(new { success = true, message = "Add successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Failed to add" }, JsonRequestBehavior.AllowGet)); } } else { if (distributorService.Edit(distributor)) { return(Json(new { success = true, message = "Edit successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Failed to edit" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Create(DistributorViewModel model) { if (!ModelState.IsValid) { return(View()); } Distributor entity = model.ToEntity(); entity.ParentId = 0; entity.AreaId = "11010000"; entity.Street = "上海"; entity.Lat = 29; entity.Lng = 30; entity.State = 1; entity.Path = "aaa"; _distributorService.Add(entity); return(RedirectToAction("Detail", entity.ToModel())); }
public object SaveDistributor(bool isEditMode, string evnt, [FromBody] Reginfo regInfo) { try { if (isEditMode != true) { regInfo.CatId = "D"; regInfo.AcTypeCode = 1; regInfo.PinStatus = "N"; regInfo.RegSource = "P"; //regInfo.RegDate = regInfo.RegDate + DateTime.Now.TimeOfDay; regInfo.RegDate = System.DateTime.Now; regInfo.EntryDate = System.DateTime.Now; string distCode = regInfo.DistCode.Substring(0, 6); var isDistCodeExist = _kycService.CheckIsDistCodeExist(distCode); if (Convert.ToInt32(isDistCodeExist) == 1) { var newDistCode = _locationService.GenerateDistributorCode(distCode); regInfo.DistCode = newDistCode.ToString(); } else { try { _distributorService.Add(regInfo); _kycService.InsertModelToAuditTrail(regInfo, regInfo.EntryBy, 3, 3, "Distributor", regInfo.Mphone, "Save successfully"); return(HttpStatusCode.OK); } catch (Exception ex) { return(HttpStatusCode.BadRequest); } } return(HttpStatusCode.OK); } else { if (evnt == "edit") { regInfo.UpdateDate = System.DateTime.Now; var prevModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _distributorService.UpdateRegInfo(regInfo); var currentModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _kycService.InsertUpdatedModelToAuditTrail(currentModel, prevModel, regInfo.UpdateBy, 3, 4, "Distributor", regInfo.Mphone, "Update successfully"); return(HttpStatusCode.OK); } else { var checkStatus = _kycService.CheckPinStatus(regInfo.Mphone); if (checkStatus.ToString() != "P") { regInfo.RegStatus = "P"; int fourDigitRandomNo = new Random().Next(1000, 9999); regInfo.AuthoDate = System.DateTime.Now; //regInfo.RegDate = _kycService.GetRegDataByMphoneCatID(regInfo.Mphone, "D"); var prevModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _distributorService.UpdateRegInfo(regInfo); _DsrService.UpdatePinNo(regInfo.Mphone, fourDigitRandomNo.ToString()); var currentModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _kycService.InsertUpdatedModelToAuditTrail(currentModel, prevModel, regInfo.AuthoBy, 3, 4, "Distributor", regInfo.Mphone, "Register successfully"); //_DsrService.UpdatePinNo(regInfo.Mphone, fourDigitRandomNo.ToString()); MessageService service = new MessageService(); service.SendMessage(new MessageModel() { Mphone = regInfo.Mphone, MessageId = "999", MessageBody = "Congratulations! Your OK wallet has been opened successfully." + " Your Pin is " + fourDigitRandomNo.ToString() + ", please change PIN to activate your account, " }); return(HttpStatusCode.OK); } else { return(HttpStatusCode.OK); } } } } catch (Exception ex) { errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()); return(HttpStatusCode.BadRequest); } }
public string BulkUploadExcel(string bulkUploadType, string distributorAC, string distributorCode, string distributorName) { string message = ""; string duplicateMsg = ""; HttpResponseMessage result = null; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { HttpPostedFile file = httpRequest.Files[0]; Stream stream = file.InputStream; IExcelDataReader reader = null; if (file.FileName.EndsWith(".xls")) { reader = ExcelReaderFactory.CreateBinaryReader(stream); } else if (file.FileName.EndsWith(".xlsx")) { reader = ExcelReaderFactory.CreateOpenXmlReader(stream); } else { message = "This file format is not supported"; } DataSet excelRecords = reader.AsDataSet(); reader.Close(); var finalRecords = excelRecords.Tables[0]; string agentCode = null; if (bulkUploadType == "Agent") { string firstClusterCode = _agentService.GetClusterCodeByTerritoryCode(distributorCode.Substring(0, 6)); agentCode = Convert.ToString(_agentService.GenerateAgentCodeAsString(firstClusterCode)); } for (int i = 1; i < finalRecords.Rows.Count; i++) { if (_distributorService.IsExistsByMpohne(finalRecords.Rows[i][0].ToString()) == false) { Reginfo objReginfo = new Reginfo(); bool isDuplicateFound = false; objReginfo.Mphone = finalRecords.Rows[i][0].ToString(); objReginfo.BankAcNo = finalRecords.Rows[i][1].ToString(); if (bulkUploadType == "Distributor") { objReginfo.CatId = "D"; } else if (bulkUploadType == "Agent") { objReginfo.CatId = "A"; objReginfo.DistCode = agentCode; } else { objReginfo.CatId = "C"; } if (_distributorService.IsExistsByCatidPhotoId(objReginfo.CatId, finalRecords.Rows[i][13].ToString()) == true) { if (!string.IsNullOrEmpty(duplicateMsg)) { duplicateMsg = duplicateMsg + " , Photo duplicate for " + finalRecords.Rows[i][0].ToString(); } else { duplicateMsg = "Photo duplicate for " + finalRecords.Rows[i][0].ToString(); } isDuplicateFound = true; } if (isDuplicateFound == false) { objReginfo.Pmphone = finalRecords.Rows[i][3].ToString(); objReginfo.BranchCode = finalRecords.Rows[i][4].ToString(); objReginfo.DateOfBirth = Convert.ToDateTime(finalRecords.Rows[i][5]); objReginfo.Name = finalRecords.Rows[i][6].ToString(); objReginfo.FatherName = finalRecords.Rows[i][7].ToString(); objReginfo.MotherName = finalRecords.Rows[i][8].ToString(); objReginfo.SpouseName = finalRecords.Rows[i][9].ToString(); objReginfo.Gender = finalRecords.Rows[i][10].ToString(); objReginfo.PhotoIdTypeCode = Convert.ToInt32(finalRecords.Rows[i][12]); objReginfo.PhotoId = finalRecords.Rows[i][13].ToString(); objReginfo.TinNo = finalRecords.Rows[i][14].ToString(); objReginfo.Religion = finalRecords.Rows[i][15].ToString(); objReginfo.Occupation = finalRecords.Rows[i][16].ToString(); objReginfo.OffMailAddr = finalRecords.Rows[i][17].ToString(); objReginfo.LocationCode = finalRecords.Rows[i][18].ToString(); //objReginfo.DistCode = agentCode; objReginfo.PreAddr = finalRecords.Rows[i][22].ToString(); objReginfo.PerAddr = finalRecords.Rows[i][23].ToString(); _distributorService.Add(objReginfo); } } else { if (!string.IsNullOrEmpty(duplicateMsg)) { duplicateMsg = duplicateMsg + " , " + finalRecords.Rows[i][0].ToString(); } else { duplicateMsg = finalRecords.Rows[i][0].ToString(); } } } //isUploaded = true; if (!string.IsNullOrEmpty(duplicateMsg)) { //message = "Excel file has been successfully uploaded"; message = "Uploaded but following are duplicate : " + duplicateMsg; } else { //message = "Excel file uploaded has fiald"; message = "Excel file has been successfully uploaded"; } } else { result = Request.CreateResponse(HttpStatusCode.BadRequest); } return(message); }