public JavaScriptResult Edit(CourierViewModel Couriervm) { try { _courierService.Update(Mapper.Map <Courier>(Couriervm)); return(JavaScript($"ShowResult('{"Data updated successfully."}','{"success"}','{"redirect"}','{"/Courier"}')")); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }
public IHttpActionResult UpdateProfileInfo(CourierDto userData) { var courier = _courierService.GetById(userData.Id); //courier = userData.MapPropertiesToInstance(courier); courier.CarNo = userData.CarNo; courier.User.Email = userData.User.Email; courier.User.MobilePhone = userData.User.MobilePhone.RemoveFormatPhone(); var newPassword = PasswordHelper.HashString(userData.User.Password, courier.User.UserName); courier.User.Password = newPassword; var result = _courierService.Update(courier); var courierDto = result.MapTo <CourierDto>(); courierDto.User.Password = userData.User.Password; return(Ok(courierDto)); }
public ActionResult Create(CourierViewModel CourierVm) { if (CourierVm.LedgerAccountGroupId == 0) { PrepareViewBag(); return(View(CourierVm).Danger("Account Group field is required")); } if (_PersonService.CheckDuplicate(CourierVm.Name, CourierVm.Suffix, CourierVm.PersonId) == true) { PrepareViewBag(); return(View(CourierVm).Danger("Combination of name and sufix is duplicate")); } if (ModelState.IsValid) { if (CourierVm.PersonId == 0) { Person person = Mapper.Map <CourierViewModel, Person>(CourierVm); BusinessEntity businessentity = Mapper.Map <CourierViewModel, BusinessEntity>(CourierVm); Courier Courier = Mapper.Map <CourierViewModel, Courier>(CourierVm); PersonAddress personaddress = Mapper.Map <CourierViewModel, PersonAddress>(CourierVm); LedgerAccount account = Mapper.Map <CourierViewModel, LedgerAccount>(CourierVm); person.CreatedDate = DateTime.Now; person.ModifiedDate = DateTime.Now; person.CreatedBy = User.Identity.Name; person.ModifiedBy = User.Identity.Name; person.ObjectState = Model.ObjectState.Added; new PersonService(_unitOfWork).Create(person); _BusinessEntityService.Create(businessentity); _CourierService.Create(Courier); personaddress.AddressType = AddressTypeConstants.Work; personaddress.CreatedDate = DateTime.Now; personaddress.ModifiedDate = DateTime.Now; personaddress.CreatedBy = User.Identity.Name; personaddress.ModifiedBy = User.Identity.Name; personaddress.ObjectState = Model.ObjectState.Added; _PersonAddressService.Create(personaddress); account.LedgerAccountName = person.Name; account.LedgerAccountSuffix = person.Suffix; account.CreatedDate = DateTime.Now; account.ModifiedDate = DateTime.Now; account.CreatedBy = User.Identity.Name; account.ModifiedBy = User.Identity.Name; account.ObjectState = Model.ObjectState.Added; _AccountService.Create(account); if (CourierVm.PanNo != "" && CourierVm.PanNo != null) { PersonRegistration personregistration = new PersonRegistration(); personregistration.RegistrationType = PersonRegistrationType.PANNo; personregistration.RegistrationNo = CourierVm.PanNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } if (CourierVm.ServiceTaxNo != "" && CourierVm.ServiceTaxNo != null) { PersonRegistration personregistration = new PersonRegistration(); personregistration.RegistrationType = PersonRegistrationType.ServiceTaxNo; personregistration.RegistrationNo = CourierVm.ServiceTaxNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } if (CourierVm.KYCNo != "" && CourierVm.KYCNo != null) { PersonRegistration personregistration = new PersonRegistration(); personregistration.RegistrationType = PersonRegistrationType.KYCNo; personregistration.RegistrationNo = CourierVm.KYCNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View(CourierVm)); } #region //Saving Images if any uploaded after UnitOfWorkSave if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { //For checking the first time if the folder exists or not----------------------------- string uploadfolder; int MaxLimit; int.TryParse(ConfigurationManager.AppSettings["MaxFileUploadLimit"], out MaxLimit); var x = (from iid in db.Counter select iid).FirstOrDefault(); if (x == null) { uploadfolder = System.Guid.NewGuid().ToString(); Counter img = new Counter(); img.ImageFolderName = uploadfolder; img.ModifiedBy = User.Identity.Name; img.CreatedBy = User.Identity.Name; img.ModifiedDate = DateTime.Now; img.CreatedDate = DateTime.Now; new CounterService(_unitOfWork).Create(img); _unitOfWork.Save(); } else { uploadfolder = x.ImageFolderName; } //For checking if the image contents length is greater than 100 then create a new folder------------------------------------ if (!Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder))) { Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)); } int count = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)).Length; if (count >= MaxLimit) { uploadfolder = System.Guid.NewGuid().ToString(); var u = new CounterService(_unitOfWork).Find(x.CounterId); u.ImageFolderName = uploadfolder; new CounterService(_unitOfWork).Update(u); _unitOfWork.Save(); } //Saving Thumbnails images: Dictionary <string, string> versions = new Dictionary <string, string>(); //Define the versions to generate versions.Add("_thumb", "maxwidth=100&maxheight=100"); //Crop to square thumbnail versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg string temp2 = ""; string filename = System.Guid.NewGuid().ToString(); foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys) { HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey]; if (pfile.ContentLength <= 0) { continue; //Skip unused file controls. } temp2 = Path.GetExtension(pfile.FileName); string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } string filecontent = Path.Combine(uploadFolder, CourierVm.Name + "_" + filename); //pfile.SaveAs(filecontent); ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true)); //Generate each version foreach (string suffix in versions.Keys) { if (suffix == "_thumb") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, CourierVm.Name + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } else if (suffix == "_medium") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, CourierVm.Name + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } } //var tempsave = _FinishedProductService.Find(pt.ProductId); person.ImageFileName = CourierVm.Name + "_" + filename + temp2; person.ImageFolderName = uploadfolder; person.ObjectState = Model.ObjectState.Modified; _PersonService.Update(person); _unitOfWork.Save(); } } #endregion //return RedirectToAction("Create").Success("Data saved successfully"); return(RedirectToAction("Edit", new { id = Courier.PersonID }).Success("Data saved Successfully")); } else { //string tempredirect = (Request["Redirect"].ToString()); Person person = Mapper.Map <CourierViewModel, Person>(CourierVm); BusinessEntity businessentity = Mapper.Map <CourierViewModel, BusinessEntity>(CourierVm); Courier Courier = Mapper.Map <CourierViewModel, Courier>(CourierVm); PersonAddress personaddress = _PersonAddressService.Find(CourierVm.PersonAddressID); LedgerAccount account = _AccountService.Find(CourierVm.AccountId); PersonRegistration PersonPan = _PersonRegistrationService.Find(CourierVm.PersonRegistrationPanNoID); PersonRegistration PersonServiceTax = _PersonRegistrationService.Find(CourierVm.PersonRegistrationServiceTaxNoID); PersonRegistration PersonKYC = _PersonRegistrationService.Find(CourierVm.PersonRegistrationKYCNoID); StringBuilder logstring = new StringBuilder(); person.ModifiedDate = DateTime.Now; person.ModifiedBy = User.Identity.Name; new PersonService(_unitOfWork).Update(person); _BusinessEntityService.Update(businessentity); _CourierService.Update(Courier); personaddress.Address = CourierVm.Address; personaddress.CityId = CourierVm.CityId; personaddress.Zipcode = CourierVm.Zipcode; personaddress.ModifiedDate = DateTime.Now; personaddress.ModifiedBy = User.Identity.Name; personaddress.ObjectState = Model.ObjectState.Modified; _PersonAddressService.Update(personaddress); account.LedgerAccountName = person.Name; account.LedgerAccountSuffix = person.Suffix; account.ModifiedDate = DateTime.Now; account.ModifiedBy = User.Identity.Name; _AccountService.Update(account); if (CourierVm.PanNo != null && CourierVm.PanNo != "") { if (PersonPan != null) { PersonPan.RegistrationNo = CourierVm.PanNo; _PersonRegistrationService.Update(PersonPan); } else { PersonRegistration personregistration = new PersonRegistration(); personregistration.PersonId = CourierVm.PersonId; personregistration.RegistrationType = PersonRegistrationType.PANNo; personregistration.RegistrationNo = CourierVm.PanNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } } if (CourierVm.ServiceTaxNo != null && CourierVm.ServiceTaxNo != "") { if (PersonServiceTax != null) { PersonServiceTax.RegistrationNo = CourierVm.ServiceTaxNo; _PersonRegistrationService.Update(PersonServiceTax); } else { PersonRegistration personregistration = new PersonRegistration(); personregistration.PersonId = CourierVm.PersonId; personregistration.RegistrationType = PersonRegistrationType.ServiceTaxNo; personregistration.RegistrationNo = CourierVm.ServiceTaxNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } } if (CourierVm.KYCNo != null && CourierVm.KYCNo != "") { if (PersonKYC != null) { PersonKYC.RegistrationNo = CourierVm.KYCNo; _PersonRegistrationService.Update(PersonKYC); } else { PersonRegistration personregistration = new PersonRegistration(); personregistration.PersonId = CourierVm.PersonId; personregistration.RegistrationType = PersonRegistrationType.KYCNo; personregistration.RegistrationNo = CourierVm.KYCNo; personregistration.CreatedDate = DateTime.Now; personregistration.ModifiedDate = DateTime.Now; personregistration.CreatedBy = User.Identity.Name; personregistration.ModifiedBy = User.Identity.Name; personregistration.ObjectState = Model.ObjectState.Added; _PersonRegistrationService.Create(personregistration); } } ////Saving Activity Log:: ActivityLog al = new ActivityLog() { ActivityType = (int)ActivityTypeContants.Modified, DocId = CourierVm.PersonId, Narration = logstring.ToString(), CreatedDate = DateTime.Now, CreatedBy = User.Identity.Name, //DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.ProcessSequence).DocumentTypeId, }; new ActivityLogService(_unitOfWork).Create(al); //End of Saving ActivityLog try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", CourierVm)); } #region //Saving Image if file is uploaded if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { string uploadfolder = CourierVm.ImageFolderName; string tempfilename = CourierVm.ImageFileName; if (uploadfolder == null) { var x = (from iid in db.Counter select iid).FirstOrDefault(); if (x == null) { uploadfolder = System.Guid.NewGuid().ToString(); Counter img = new Counter(); img.ImageFolderName = uploadfolder; img.ModifiedBy = User.Identity.Name; img.CreatedBy = User.Identity.Name; img.ModifiedDate = DateTime.Now; img.CreatedDate = DateTime.Now; new CounterService(_unitOfWork).Create(img); _unitOfWork.Save(); } else { uploadfolder = x.ImageFolderName; } } //Deleting Existing Images var xtemp = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename); if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename)); } //Deleting Thumbnail Image: if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename)); } //Deleting Medium Image: if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename)); } //Saving Thumbnails images: Dictionary <string, string> versions = new Dictionary <string, string>(); //Define the versions to generate versions.Add("_thumb", "maxwidth=100&maxheight=100"); //Crop to square thumbnail versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg string temp2 = ""; string filename = System.Guid.NewGuid().ToString(); foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys) { HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey]; if (pfile.ContentLength <= 0) { continue; //Skip unused file controls. } temp2 = Path.GetExtension(pfile.FileName); string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } string filecontent = Path.Combine(uploadFolder, CourierVm.Name + "_" + filename); //pfile.SaveAs(filecontent); ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true)); //Generate each version foreach (string suffix in versions.Keys) { if (suffix == "_thumb") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, CourierVm.Name + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } else if (suffix == "_medium") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, CourierVm.Name + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } } } var temsave = _PersonService.Find(person.PersonID); temsave.ImageFileName = temsave.Name + "_" + filename + temp2; temsave.ImageFolderName = uploadfolder; _PersonService.Update(temsave); _unitOfWork.Save(); } #endregion return(RedirectToAction("Index").Success("Data saved successfully")); } } PrepareViewBag(); return(View(CourierVm)); }