public IActionResult Feedback7(Feedback7 feedback) { try { //id = (int)Decimal.Parse(feedbackid, NumberStyles.Currency, CultureInfo.InvariantCulture); using (yetkilimDBContext db = new yetkilimDBContext()) { var userId = 0; if (base.CurrentUser != null) { userId = base.CurrentUser.UserId; } try { if (feedback.IsUserShare.HasValue && feedback.IsUserShare.Value) { var user = db.Users.AsNoTracking().FirstOrDefault(x => x.Id == userId); feedback.UserFullName = user.Name; feedback.UserMail = user.Email; feedback.UserPhone = user.Phone; } } catch (Exception) { } feedback.CreatedDate = DateTime.Now; feedback.UserId = userId; try { feedback.IpAddress = this.Request.HttpContext.Connection .RemoteIpAddress .ToString(); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "IP Address error", Array.Empty <object>()); } db.Feedback7.Add(feedback); db.SaveChanges(); try { var listMail = new List <string>(); var userPlaces = db.PanelUser.AsNoTracking().Where(x => x.PlaceId == feedback.PlaceId && !x.IsDeleted).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.AsNoTracking().Where(x => x.CompanyId == place.CompanyId && !x.IsDeleted).ToList(); if (userCompanies != null && userCompanies.Any()) { listMail.AddRange(userCompanies.Where(x => !string.IsNullOrWhiteSpace(x.Email)).Select(x => x.Email)); } _emailSender.Send( listMail.ToArray() , "Müşteriniz işletmeniz için bir değerlendirme yaptı", myTableMaker(new Feedback7[] { feedback }, "7")); } catch (Exception) { } } } catch (Exception ex) { return(Content(ex.ToString())); } return(new EmptyResult()); }
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 async Task <ViewResult> Update(int id, PlaceFormModel model) { if (this.ModelState.IsValid) { try { PlaceDTO placeDTO = Mapper.Map <PlaceFormModel, PlaceDTO>(model); placeDTO.CompanyId = ((base.CurrentUser.Role != UserRole.SuperAdmin) ? base.CurrentUser.CompanyId : 0); Result result = await _placeService.UpdatePlaceAsync(id, placeDTO); 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 placeUsers = db.PanelUser.Where(x => x.PlaceId == id && !x.IsDeleted).ToList(); for (int i = 0; i < placeUsers.Count; i++) { try { string pass = PasswordHelper.GeneratePassword(6); placeUsers[i].Password = PasswordHelper.MD5Hash(pass); db.Entry(placeUsers[i]).State = EntityState.Modified; db.SaveChanges(); await _emailSender.Send(new string[] { placeUsers[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) // { // ; // } } } } model.IsSuperAdmin = (base.CurrentUser.Role == UserRole.SuperAdmin); 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."; model.IsSuperAdmin = (base.CurrentUser.Role == UserRole.SuperAdmin); return(this.View((object)model)); } } model.IsSuperAdmin = (base.CurrentUser.Role == UserRole.SuperAdmin); return(this.View((object)model)); }