public async Task <Responce <bool> > UpdateCityMail(ChnageCityMailRequest chnageCityMailRequest) { Responce <bool> Responce = new Responce <bool>(); Responce.Success = true; try { using (var db = new SSCEntities()) { Citys citys = db.Citys.Find(chnageCityMailRequest.Cityid); citys.MCEmail = chnageCityMailRequest.MCEmail; citys.FcciEmail = chnageCityMailRequest.FCCIEmail; db.Entry(citys).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); Responce.ResponeContent = true; } } catch (Exception ex) { Responce.Success = false; Responce.ResponeContent = false; Responce.Message = $"ERROR UpdateCityMail :{ex.InnerException}"; } return(Responce); }
public async Task <IHttpActionResult> UpdateUserInfo(UpdateUserInfoRequest model) { Responce <UserInfoViewModel> responce = new Responce <UserInfoViewModel>(); responce.Success = true; try { string City = ""; string UserId = ""; #pragma warning disable CS0219 // The variable 'CityId' is assigned but its value is never used string CityId = ""; #pragma warning restore CS0219 // The variable 'CityId' is assigned but its value is never used string Name = ""; string PhoneNumber = ""; var UserRole = await UserManager.GetRolesAsync(User.Identity.GetUserId()); //IdentityUser user = await UserManager.FindByIdAsync(model.UserId); using (SSCEntities db = new SSCEntities()) { var AspNetUser = db.AspNetUsers.Find(model.UserId); AspNetUser.City = model.City; AspNetUser.Name = model.Name; AspNetUser.PhoneNumber = model.PhoneNumber; AspNetUser.CityId = model.CityId; db.Entry(AspNetUser).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); City = AspNetUser.City; UserId = AspNetUser.Id; PhoneNumber = AspNetUser.PhoneNumber; Name = AspNetUser.Name; responce.ResponeContent = new UserInfoViewModel { Email = AspNetUser.Email, City = City, UserId = UserId, PhoneNumber = PhoneNumber, Name = Name, UserRole = UserRole.FirstOrDefault() }; } return(Ok(responce)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IHttpActionResult> SendMail(MobileRequest mobileRequest) { Boolean EmailTest = false; string EmailTestTo = "*****@*****.**"; if (ConfigurationManager.AppSettings.AllKeys.Contains("EmailTest")) { EmailTest = Convert.ToBoolean(ConfigurationManager.AppSettings["EmailTest"].ToString()); } if (ConfigurationManager.AppSettings.AllKeys.Contains("EmailTestTo")) { EmailTestTo = ConfigurationManager.AppSettings["EmailTestTo"].ToString(); } Responce <List <bool> > responce = new Responce <List <bool> >(); responce.Success = true; try { using (var SSCEntities = new SSCEntities()) { var complaints = SSCEntities.Complaints.Find(mobileRequest.Id); if (complaints != null && complaints.IsEmailSend == false) { await SendMailMethod(complaints, EmailTest?EmailTestTo : complaints.Citys.FcciEmail); await SendMailMethod(complaints, EmailTest?EmailTestTo : complaints.Citys.MCEmail); complaints.IsEmailSend = true; complaints.ComplainStatus = (int)ComplaintStatusEnum.Registered; SSCEntities.Entry(complaints).State = System.Data.Entity.EntityState.Modified; await SSCEntities.SaveChangesAsync(); } } } #pragma warning disable CS0168 // The variable 'ex' is declared but never used catch (Exception ex) #pragma warning restore CS0168 // The variable 'ex' is declared but never used { responce.Success = false; } return(Ok(responce)); }
public async Task <Responce <ComplaintsDTO> > SaveComplaint(HttpRequest complaintRequest, string UserName) { Responce <ComplaintsDTO> Responce = new Responce <ComplaintsDTO>(); Responce.Success = true; try { using (SSCEntities = new SSCEntities()) { Complaints complaints = new Complaints(); int Id = Convert.ToInt32(complaintRequest.Form["Id"]); var Cityid = Convert.ToInt32(complaintRequest.Form["Cityid"]); var SpeciesId = Convert.ToInt32(complaintRequest.Form["SpeciesId"]); complaints.City = Cityid; complaints.Id = Id; if (complaints.Id != 0) { complaints = SSCEntities.Complaints.Find(Id); var ComplaintLows = complaints.ComplaintsLows; var ComplaintImages = complaints.ComplaintImages; SSCEntities.ComplaintsLows.RemoveRange(ComplaintLows); SSCEntities.ComplaintImages.RemoveRange(ComplaintImages); await SSCEntities.SaveChangesAsync(); } complaints.SpeciesId = SpeciesId; complaints.ShopName = Convert.ToString(complaintRequest.Form["ShopName"]); complaints.ShopAddress = Convert.ToString(complaintRequest.Form["ShopAddress"]); complaints.DateOfInspection = Convert.ToDateTime(complaintRequest.Form["DateOfInspection"]); complaints.Comments = Convert.ToString(complaintRequest.Form["Comments"]); complaints.Violations = Convert.ToString(complaintRequest.Form["Violations"]); complaints.GpsLocations = Convert.ToString(complaintRequest.Form["GpsLocations"]); complaints.UserId = Convert.ToString(complaintRequest.Form["UserId"]); complaints.ComplainStatus = Convert.ToInt32(complaintRequest.Form["ComplainStatus"]); complaints.GroupName = Convert.ToString(complaintRequest.Form["GroupName"]); complaints.IsDelete = Convert.ToBoolean(complaintRequest.Form["IsDelete"]); complaints.IsActive = Convert.ToBoolean(complaintRequest.Form["IsActive"]); complaints.ModifiedBy = UserName ?? Convert.ToString(complaintRequest.Form["UserId"]); complaints.ModifiedDate = DateTime.UtcNow; complaints.IsRejecet = Convert.ToBoolean(complaintRequest.Form["IsRejecet"]); complaints.CommentForRejection = Convert.ToString(complaintRequest.Form["CommentForRejection"]); complaints.RegistrationDate = Convert.ToDateTime(complaintRequest.Form["RegistrationDate"]); complaints.IsRegister = Convert.ToBoolean(complaintRequest.Form["IsRegister"]); complaints.IsEmailSend = Convert.ToBoolean(complaintRequest.Form["IsEmailSend"]); if (complaints.Id != 0) { SSCEntities.Entry(complaints).State = EntityState.Modified; } else { complaints.CreatedBy = UserName ?? Convert.ToString(complaintRequest.Form["UserId"]); complaints.CreatedDate = DateTime.UtcNow; SSCEntities.Complaints.Add(complaints); } await SSCEntities.SaveChangesAsync(); var LowsIds = Convert.ToString(complaintRequest.Form["LowIds"]).Split(','); if (LowsIds.Count() > 0) { foreach (var item in LowsIds) { ComplaintsLows complaintsLows = new ComplaintsLows(); complaintsLows.LowId = Convert.ToInt32(item); complaintsLows.ComplaintId = complaints.Id; SSCEntities.ComplaintsLows.Add(complaintsLows); await SSCEntities.SaveChangesAsync(); } } if (complaintRequest.Files != null) { if (complaintRequest.Files.Count > 0) { for (int i = 0; i < complaintRequest.Files.Count; i++) { if (complaintRequest.Files[i].ContentLength > 0) { ComplaintImages complaintsImages = new ComplaintImages(); string extension = Path.GetExtension(complaintRequest.Files[i].FileName); bool isImage = Functions.IsImage(complaintRequest.Files[i].FileName); string ContentType = complaintRequest.Files[i].ContentType; string[] bloburi = AzureStore.UploadFile(complaintRequest.Files[i].InputStream, complaintRequest.Files[i].FileName, ContentType, isImage, extension); complaintsImages.ComplaintId = complaints.Id; complaintsImages.Imagetype = extension; complaintsImages.ImageUrl = bloburi[0]; complaintsImages.CreatedDate = DateTime.UtcNow; complaintsImages.ModifiedDate = DateTime.UtcNow; complaintsImages.CreatedBy = UserName; complaintsImages.ModifiedBy = UserName; SSCEntities.ComplaintImages.Add(complaintsImages); await SSCEntities.SaveChangesAsync(); } } //foreach (string item in complaintRequest.Files) //{ // var postedFile = complaintRequest.Files[item]; // if (!string.IsNullOrEmpty(postedFile.FileName)) // { // ComplaintImages complaintsImages = new ComplaintImages(); // string extension = Path.GetExtension(postedFile.FileName); // } // i = i + 1; //} } } ComplaintsDTO complaintsdto = new ComplaintsDTO(); SSCEntities db = new SSCEntities(); var saveComplaintobj = db.Complaints.Find(complaints.Id); complaintsdto = saveComplaintobj.MapComplaintsToDTO(); Responce.ResponeContent = complaintsdto; } } catch (Exception ex) { Responce.Success = false; Responce.Message = $"ERROR SaveComplaint :{ex.ToString()}"; } return(Responce); }
public async Task <Responce <bool> > UpsertCity(CityDTO model) { Responce <bool> Responce = new Responce <bool>(); Responce.Success = true; try { using (var db = new SSCEntities()) { if (model.IsCreate) { } else { } var IsAdminEmailExist = db.AspNetUsers.Where(a => a.Email.ToLower() == model.AdminEmail.ToLower())?.ToList(); if (IsAdminEmailExist.Count > 0) { DateTime dateTime = DateTime.UtcNow; Citys citys = db.Citys.Find(model.Id) ?? new Citys(); citys.MCEmail = model.MCEmail; citys.FcciEmail = model.FcciEmail; citys.CityName = model.CityName; citys.IsActive = model.IsActive; citys.AdminEmail = model.AdminEmail; if (citys.Id == 0) { citys.CreatedBy = model.CreatedBy; citys.CreatedDate = dateTime; citys.ModifiedBy = model.ModifiedBy; citys.ModifiedDate = dateTime; db.Entry(citys).State = System.Data.Entity.EntityState.Added; await db.SaveChangesAsync(); } else { citys.ModifiedBy = model.ModifiedBy; citys.ModifiedDate = dateTime; citys.ModifiedBy = model.ModifiedBy; citys.ModifiedDate = DateTime.UtcNow; db.Entry(citys).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } Responce.ResponeContent = true; } else { Responce.ResponeContent = false; Responce.Success = false; Responce.Message = "Admin email is not register"; } } } catch (Exception ex) { Responce.Success = false; Responce.ResponeContent = false; Responce.Message = $"ERROR UpsertCity :{ex.InnerException}"; } return(Responce); }
public async Task <IHttpActionResult> UpdateCity(CityDTO citydto) { Responce <bool> responce = new Responce <bool>(); try { using (var db = new SSCEntities()) { var CheckCity = db.Citys.Find(citydto.Id); if (CheckCity == null) { responce.ResponeContent = false; responce.Success = false; responce.Message = "This city should not exist"; return(Content(HttpStatusCode.BadRequest, responce)); } var GetDefaultCityAdminUser = db.AspNetUsers.Where(a => a.IsDefaultAdmin == true && a.CityId == citydto.Id)?.FirstOrDefault(); if (GetDefaultCityAdminUser != null) { var appUser = await UserManager.FindByNameAsync(GetDefaultCityAdminUser.UserName); if (appUser != null) { if (appUser.UserName.ToLower() != citydto.AdminEmail.ToLower()) { appUser.UserName = citydto.AdminEmail; appUser.Email = citydto.AdminEmail; //appUser.City = citydto.CityName; //appUser.CityId = citydto.Id; IdentityResult result = await UserManager.UpdateAsync(appUser); if (!result.Succeeded) { var Errors = GetIdentityErrorResult(result); responce.Fail(Errors); responce.ResponeContent = false; return(Content(HttpStatusCode.BadRequest, responce)); } } } } DateTime dateTime = DateTime.UtcNow; Citys citys = CheckCity; citys.MCEmail = citydto.MCEmail; citys.FcciEmail = citydto.FcciEmail; citys.CountryId = citydto.CountryId ?? 1; citys.CityName = citydto.CityName; citys.IsActive = citydto.IsActive; citys.AdminEmail = citydto.AdminEmail; citys.ModifiedBy = citydto.ModifiedBy; citys.ModifiedDate = dateTime; db.Entry(citys).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); List <AspNetUsers> aspNetUsers = new List <AspNetUsers>(); aspNetUsers = db.AspNetUsers.Where(a => a.CityId == citys.Id).ToList(); foreach (var item in aspNetUsers) { item.City = citys.CityName; db.Entry(item).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } responce.Success = true; responce.ResponeContent = true; } return(Ok(responce)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IHttpActionResult> CreateCity(CityDTO citydto) { Responce <bool> responce = new Responce <bool>(); try { var IsUserExist = await UserManager.FindByNameAsync(citydto.AdminEmail); if (IsUserExist != null) { var Errors = "User email already registered."; responce.Fail(Errors); responce.ResponeContent = false; return(Content(HttpStatusCode.BadRequest, responce)); } using (var db = new SSCEntities()) { var CheckCity = db.Citys.Where(a => a.CityName.ToLower() == citydto.CityName.ToLower())?.ToList() ?? new List <Citys>(); if (CheckCity.Count > 0) { responce.ResponeContent = false; responce.Success = false; responce.Message = "City already added"; return(Content(HttpStatusCode.BadRequest, responce)); } DateTime dateTime = DateTime.UtcNow; Citys citys = new Citys(); citys.MCEmail = citydto.MCEmail; citys.FcciEmail = citydto.FcciEmail; citys.CityName = citydto.CityName; citys.IsActive = citydto.IsActive; citys.AdminEmail = citydto.AdminEmail; citys.CreatedBy = citydto.CreatedBy; citys.CreatedDate = dateTime; citys.ModifiedBy = citydto.ModifiedBy; citys.ModifiedDate = dateTime; db.Entry(citys).State = System.Data.Entity.EntityState.Added; await db.SaveChangesAsync(); var lows = db.Lows.ToList(); SSCEntities sscEntities = new SSCEntities(); foreach (var item in lows) { CityLows cityLows = new CityLows(); cityLows.Id = citys.Id; cityLows.LowId = item.Id; sscEntities.Entry(cityLows).State = System.Data.Entity.EntityState.Added; await sscEntities.SaveChangesAsync(); } var user = new ApplicationUser() { UserName = citydto.AdminEmail, Email = citydto.AdminEmail, City = citydto.CityName, PhoneNumber = citydto.MobileNo, Name = citydto.UserName, IsDefaultAdmin = true, CityId = citys.Id }; IdentityResult result = await UserManager.CreateAsync(user, citydto.Password); if (!result.Succeeded) { var Errors = GetIdentityErrorResult(result); responce.Fail(Errors); responce.ResponeContent = false; return(Content(HttpStatusCode.BadRequest, responce)); } db.UpdateUserRole("989D2937-0FC5-497D-980C-B2E8583602B9", user.Id); responce.ResponeContent = true; responce.Success = true; } return(Ok(responce)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }