public async Task <IActionResult> Update(int id) { if (base.CurrentUser.Role != UserRole.Dealer && (base.CurrentUser.Role != UserRole.Admin || base.CurrentUser.CompanyId == id)) { CompanyFormModel model = new CompanyFormModel(); try { Result <CompanyDetailDTO> result = await _companyService.GetCompanyAsync(id); if (result.IsSuccess) { model = Mapper.Map <CompanyDetailDTO, CompanyFormModel>(result.Data); } else { model.FormMessage = result.FormMessage; } model.IsUpdate = true; return(this.View((object)model)); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "GET Update Error {0}", new object[1] { id }); model.FormMessage = "İşleminiz gerçekleştirilemedi."; return(this.View((object)model)); } } return(this.RedirectToAction("Index", "Manage")); }
public async Task <IActionResult> Create(CompanyFormModel model) { if (this.ModelState.IsValid) { try { if (string.IsNullOrWhiteSpace(model.ManagerName) || string.IsNullOrWhiteSpace(model.ManagerEmail)) { model.IsSuccess = false; model.FormMessage = "Firma yetkilisi bilgileri girilmelidir."; return(this.View((object)model)); } IFormFile logoFile = model.LogoFile; string uniqueFileName = null; if (logoFile != null && logoFile.Length > 0) { uniqueFileName = FileHelper.GetUniqueFileName(logoFile.FileName); if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath)) { _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } string path = Path.Combine(_hostingEnvironment.WebRootPath, "admin/uploads"); string path2 = Path.Combine(path, uniqueFileName); using (FileStream stream = new FileStream(path2, FileMode.Create)) { await logoFile.CopyToAsync((Stream)stream, default(CancellationToken)); } } CompanyDetailDTO companyDetailDTO = Mapper.Map <CompanyFormModel, CompanyDetailDTO>(model); companyDetailDTO.Image = uniqueFileName; PanelUserDTO manager = new PanelUserDTO { Email = model.ManagerEmail, Name = model.ManagerName, Surname = model.ManagerSurname }; Result <CompanyDetailDTO> result = await _companyService.AddCompanyAsync(companyDetailDTO, manager); model.FormMessage = result.FormMessage; model.IsSuccess = result.IsSuccess; if (model.IsSuccess) { model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi."; } return(this.View((object)model)); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "Create Error", Array.Empty <object>()); model.IsSuccess = false; model.FormMessage = "İşleminiz gerçekleştirilemedi."; return(this.View((object)model)); } } return(this.View((object)model)); }
public async Task <IActionResult> Update(int id, CompanyFormModel model) { if (base.CurrentUser.Role != UserRole.SuperAdmin && base.CurrentUser.CompanyId != id) { return(this.RedirectToAction("Index", "Manage")); } model.IsUpdate = true; if (this.ModelState.IsValid) { try { CompanyDetailDTO company = Mapper.Map <CompanyFormModel, CompanyDetailDTO>(model); IFormFile logoFile = model.LogoFile; if (logoFile != null) { string uniqueFileName = FileHelper.GetUniqueFileName(logoFile.FileName); if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath)) { _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } string path = Path.Combine(_hostingEnvironment.WebRootPath, "admin/uploads"); string path2 = Path.Combine(path, uniqueFileName); using (FileStream stream = new FileStream(path2, FileMode.Create)) { await logoFile.CopyToAsync((Stream)stream, default(CancellationToken)); } company.Image = uniqueFileName; model.Image = uniqueFileName; } Result result = await _companyService.UpdateCompanyAsync(id, company); model.FormMessage = result.FormMessage; model.IsSuccess = result.IsSuccess; if (model.IsSuccess) { model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi."; } if (result.Messages != null && result.Messages.Any()) { var temp = result.Messages.FirstOrDefault(x => string.Equals(x, "Demo", StringComparison.InvariantCultureIgnoreCase)); if (temp != null) { using (yetkilimDBContext db = new yetkilimDBContext()) { var listMail = new List <string>(); //var userPlaces = db.PanelUser.AsNoTracking().Where(x => x.PlaceId == feedback.PlaceId).ToList(); //if (userPlaces != null && userPlaces.Any()) //{ // listMail.AddRange(userPlaces.Where(x => !string.IsNullOrWhiteSpace(x.Email)).Select(x => x.Email)); //} //var place = db.Places.First(x => x.Id == feedback.PlaceId); var userCompanies = db.PanelUser.Where(x => x.CompanyId == id && !x.IsDeleted).ToList(); for (int i = 0; i < userCompanies.Count; i++) { try { string pass = PasswordHelper.GeneratePassword(6); userCompanies[i].Password = PasswordHelper.MD5Hash(pass); db.Entry(userCompanies[i]).State = EntityState.Modified; db.SaveChanges(); await _emailSender.Send(new string[] { userCompanies[i].Email }, "Yeni şireniz", pass); } catch (Exception ex) { } } // if (userCompanies != null && userCompanies.Any()) // { // listMail.AddRange(userCompanies.Where(x => !string.IsNullOrWhiteSpace(x.Email)).Select(x => x.Email)); // } // foreach (var item in listMail) // { // ; // } } } } return(this.View((object)model)); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "POST Update Error {0}", new object[1] { id }); model.FormMessage = "İşleminiz gerçekleştirilemedi."; return(this.View((object)model)); } } return(this.View((object)model)); }
public IActionResult Create() { CompanyFormModel companyFormModel = new CompanyFormModel(); return(this.View((object)companyFormModel)); }