public ActionResult BlockCustomer(Guid id) { //UserPermissionAction("Account", RoleAction.detail.ToString()); //CheckPermission(); if (Session["UserId"] == null) { return(RedirectToAction("LogOn", "Account")); } Customer objCustomer = _CustomerService.GetCustomer(id); try { if (objCustomer != null) { objCustomer.IsActive = false; _CustomerService.UpdateCustomer(objCustomer); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = "Account successfully deactivated."; CommonCls.SendMailOfAccountIsActive(objCustomer.FirstName, objCustomer.EmailId, "deactivated"); string UserMessage = "Your account has been deactivated by admin."; string Message = "{\"flag\":\"" + "Deactivate" + "\",\"UserMessage\":\"" + UserMessage + "\"}"; var customerTo = objCustomer; if (customerTo.ApplicationId != null && customerTo.ApplicationId != "") { if (customerTo.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { //Send Notification another Andriod CommonCls.SendFCM_Notifications(customerTo.ApplicationId, Message, true); } else { string Msg = UserMessage; CommonCls.TestSendFCM_Notifications(customerTo.ApplicationId, Message, Msg, true); } } return(RedirectToAction("Individuals")); } } catch (Exception ex) { ErrorLogging.LogError(ex); RedirectToAction("Individuals"); } return(RedirectToAction("Individuals")); }
public void SendNotificationsToUsers(int CustomerId, string Heading, string Message, string ImageUrl, string IsWithImage, int count) { string Flag = "15"; //send notification // var Customers = _CustomerService.GetCustomers().Where(c => c.CustomerId != CustomerId && c.IsActive == true).ToList(); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select * From Customer where CustomerId = " + CustomerId + " and IsActive=1"; dt = CommonClass.GetDataSet(QStr).Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { var ApplicationId = dr["ApplicationId"].ToString(); var DeviceType = dr["DeviceType"].ToString(); //var IsNotificationSoundOn = Convert.ToBoolean(dr["IsNotificationSoundOn"]); var IsNotificationSoundOn = true; string sql = "insert into [notification](RequestMessage,NotificationSendTo,NotificationSendBy,Flag,IsRead) values(@RequestMessage,@NotificationSendTo,@NotificationSendBy,@Flag,@IsRead)"; try { string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { using (SqlCommand cmd = new SqlCommand(sql, con)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@RequestMessage", Message); cmd.Parameters.AddWithValue("@NotificationSendTo", dr["CustomerId"].ToString()); cmd.Parameters.AddWithValue("@NotificationSendBy", CustomerId); cmd.Parameters.AddWithValue("@Flag", Flag); cmd.Parameters.AddWithValue("@IsRead", false); con.Open(); int rowsAffected = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); con.Dispose(); } } } catch (Exception ex) { } if (ApplicationId != null && ApplicationId != "") { bool NotificationStatus = true; string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\",\"Heading\":\"" + Heading + "\",\"ImageUrl\":\"" + ImageUrl + "\",\"IsWithImage\":\"" + IsWithImage + "\"}"; if (DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { CommonCls.SendGCM_Notifications(ApplicationId, JsonMessage, true); } else { string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { con.Open(); using (SqlCommand thisCommand = new SqlCommand("SELECT COUNT(*) FROM Notification where NotificationSendTo=@NotificationSendTo and isread=0 ", con)) { thisCommand.Parameters.AddWithValue("@NotificationSendTo", Convert.ToInt32(dr["CustomerId"].ToString())); count = (int)(thisCommand.ExecuteScalar()); } con.Close(); con.Dispose(); } //Dictionary<string, object> Dictionary = new Dictionary<string, object>(); //Dictionary.Add("Flag", Flag); //Dictionary.Add("Message", Message); //NotificationStatus = PushNotificatinAlert.SendPushNotification(ApplicationId, Message, Flag.ToString(), JsonMessage, Dictionary, 1, Convert.ToBoolean(IsNotificationSoundOn)); CommonCls.TestSendFCM_Notifications(ApplicationId, JsonMessage, Message, count, true); } } } } }
public HttpResponseMessage SaveChat([FromBody] ChatModel chatModel) { string ChatID = "-1"; try { if (chatModel.CustomerIdBy == new Guid()) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CustomerId By is blank."), Configuration.Formatters.JsonFormatter)); } if (chatModel.CustomerIdTo == new Guid()) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CustomerId To is blank."), Configuration.Formatters.JsonFormatter)); } var customerTo = _CustomerService.GetCustomer(chatModel.CustomerIdTo); if (customerTo == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer To not found."), Configuration.Formatters.JsonFormatter)); } var customerBy = _CustomerService.GetCustomer(chatModel.CustomerIdBy); if (customerBy == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer By not found."), Configuration.Formatters.JsonFormatter)); } if (chatModel.ChatContent != null && chatModel.ChatContent != "") { List <Guid?> ListCustomerIDs = new List <Guid?>(); ListCustomerIDs.Add(chatModel.CustomerIdBy); ListCustomerIDs.Add(chatModel.CustomerIdTo); var isFriend = _RequestService.GetRequests().Where(x => ListCustomerIDs.Contains(x.CustomerIdBy) && ListCustomerIDs.Contains(x.CustomerIdTo)).FirstOrDefault(); if (isFriend != null) { Mapper.CreateMap <HomeHelp.Models.ChatModel, HomeHelp.Entity.Chat>(); HomeHelp.Entity.Chat chat = Mapper.Map <HomeHelp.Models.ChatModel, HomeHelp.Entity.Chat>(chatModel); if (chatModel.ChatId <= 0) { TimeZoneInfo tz = TimeZoneInfo.Local; chat.DateTimeCreated = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, tz); _ChatService.Insert(chat); //Save Operation ChatID = chat.ChatId.ToString(); } // Code For GCM & Iphone //var Customer = _CustomerService.GetCustomer(Convert.ToInt32(chatModel.CustomerIdTo)); //if (Customer != null) //{ // var Chats = _ChatService.GetAll().ToList(); // var Results = (from m in Chats // where m.CustomerIdTo == chatModel.CustomerIdTo && m.IsRead == false // group m by new { m.CustomerIdTo } into g // select new // { // CustomerIdBy = g.Key.CustomerIdTo, // ChatContent = (from c in Chats // where c.CustomerIdTo == chatModel.CustomerIdTo && c.IsRead == false // orderby c.DateTimeCreated descending // select c.ChatContent).FirstOrDefault(), // Count = g.Count() // }).ToList(); // var models = new List<ChatModel>(); // var UserMessage = ""; // bool NotificationStatus = true; // if (Results.Count() >= 0) // { // int MessageCount = Convert.ToInt32(Results.Sum(x => x.Count).ToString()) + 1; string UserMessage = "You have new message."; string NotificationType = "chat"; string Flag = "NewChatMessage"; //Save notification in Table Notification Notification = new Notification(); Notification.NotificationId = 0; //New Case //Notification.ClientId = _Event.ClientID; Save it as NULL Notification.CustomerIdBy = customerBy.CustomerId; Notification.CustomerIdTo = customerTo.CustomerId; //Notification.EventID = _Event.EventID; Save it as NULL Notification.UserMessage = UserMessage; Notification.NotificationType = NotificationType; Notification.Flag = Flag; Notification.DeviceType = customerBy.DeviceType; _NotificationService.InsertNotification(Notification); // //End : Save notification in Table // string Message = "{\"flag\":\"" + Flag + "\",\"message\":\"" + UserMessage + "\",\"ChatContent\":\"" + chatModel.ChatContent + "\"}"; string Message = "{ \"ChatId\": \"" + ChatID + "\", \"CustomerIdBy\": \"" + customerBy.CustomerId + "\", \"CustomerIdTo\": \"" + customerTo.CustomerId + "\", \"ChatContent\": \"" + chatModel.ChatContent + "\", \"flag\": \"" + Flag + "\", \"IsRead\": \"" + chat.IsRead + "\", \"IsDeletedCustomerBy\":\"" + chat.IsDeletedCustomerBy + "\", \"IsDeletedCustomerTo\": \"" + chat.IsDeletedCustomerTo + "\", \"DateTimeCreated\": \"" + chat.DateTimeCreated + "\", \"CustomersBy\": { \"CustomerId\": \"" + customerBy.CustomerId + "\", \"FirstName\": \"" + customerBy.FirstName + "\", \"LastName\": \"" + customerBy.LastName + "\", \"PhotoPath\": \"" + customerBy.PhotoPath + "\" }, \"CustomersTo\": { \"CustomerId\": \"" + customerTo.CustomerId + "\", \"FirstName\": \"" + customerTo.FirstName + "\", \"LastName\": \"" + customerTo.LastName + "\", \"PhotoPath\": \"" + customerTo.PhotoPath + "\" } }"; if (customerTo.ApplicationId != null && customerTo.ApplicationId != "") { if (customerTo.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { //Send Notification another Andriod CommonCls.SendFCM_Notifications(customerTo.ApplicationId, Message, true); } else { string Msg = customerTo.FirstName + " " + customerTo.LastName + " : " + chat.ChatContent; CommonCls.TestSendFCM_Notifications(customerTo.ApplicationId, Message, Msg, true); //CommonCls.TestSendFCM_Notifications(customerTo.ApplicationId, Message, true); } } Mapper.CreateMap <HomeHelp.Entity.Chat, HomeHelp.Models.ChatResponseModel>(); HomeHelp.Models.ChatResponseModel ChatModel = Mapper.Map <HomeHelp.Entity.Chat, HomeHelp.Models.ChatResponseModel>(chat); string sqlFormattedDate = chat.DateTimeCreated.HasValue ? chat.DateTimeCreated.Value.ToString("yyyy-MM-dd HH:mm:ss.fff") : ""; ChatModel.DateTimeCreated = sqlFormattedDate; return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", ChatModel), Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "they are not associated."), Configuration.Formatters.JsonFormatter)); } } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Chat content is blank."), Configuration.Formatters.JsonFormatter)); } } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); ErrorLogging.LogError(ex); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try later"), Configuration.Formatters.JsonFormatter)); } }
public ActionResult AssignRequest(Guid assignedId, int jobRequestId) { string UserMessage = ""; string Flag = ""; if (Session["UserId"] == null) { return(RedirectToAction("LogOn", "Account")); } if (assignedId == null || jobRequestId == 0) { return(Json(true, JsonRequestBehavior.AllowGet)); } else { RequestModel requestModel = new RequestModel(); Mapper.CreateMap <JobRequest, RequestModel>(); var jobRequestDetail = _RequestService.GetRequest(jobRequestId); var customerToData = _AgencyIndividualService.GetAgencyIndividual(assignedId); var data = _CustomerService.GetCustomerByUserId(customerToData.UserId); int id = Convert.ToInt32(Session["UserId"].ToString()); if (id > 0) { var assignedBy = _AgencyIndividualService.GetAgencyIndividualByUserId(id); UserMessage = "You have new job request by " + assignedBy.FullName; Flag = "NewRequest"; Notification notification = new Notification(); notification.CustomerIdBy = assignedBy.AgencyIndividualId; //notification.CustomerIdTo = data.CustomerId; notification.CustomerIdTo = data.CustomerId; notification.SourceId = jobRequestDetail.JobRequestId; notification.UserMessage = UserMessage; //notification.NotificationType = Convert.ToString(EnumValue.NotificationType.Request); notification.Flag = Flag; notification.DeviceType = data.DeviceType; notification.NotificationStatus = EnumValue.GetEnumDescription(EnumValue.RequestStatus.New); _NotificationService.InsertNotification(notification); string Message = "{\"flag\":\"" + Flag + "\",\"JobRequestId\":\"" + jobRequestDetail.JobRequestId + "\",\"UserMessage\":\"" + UserMessage + "\"}"; if (data.ApplicationId != null && data.ApplicationId != "") { if (data.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { //Send Notification another Andriod CommonCls.SendFCM_Notifications(data.ApplicationId, Message, true); } else { string Msg = UserMessage; CommonCls.TestSendFCM_Notifications(data.ApplicationId, Message, Msg, true); } } } else { return(RedirectToAction("LogOn", "Account")); } jobRequestDetail.CustomerIdTo = data.CustomerId; var assignedJob = _AgencyJobService.GetAgencyJobByJobRequest(jobRequestDetail.JobRequestId); assignedJob.AgencyIndividualId = data.CustomerId; if (jobRequestDetail.JobStatus == EnumValue.GetEnumDescription(EnumValue.RequestStatus.Declined)) { jobRequestDetail.RequestStatus = EnumValue.GetEnumDescription(EnumValue.RequestStatus.New); jobRequestDetail.JobStatus = EnumValue.GetEnumDescription(EnumValue.JobStatus.Pending); assignedJob.Status = EnumValue.GetEnumDescription(EnumValue.JobStatus.Pending); } _RequestService.UpdateRequest(jobRequestDetail); _AgencyJobService.UpdateAgencyJob(assignedJob); return(Json(true, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit([Bind(Include = "CustomerId,TrebId,WebsiteUrl,ApplicationID,Password,CompanyID,UserId,PhotoPath,FirstName,LastName,MiddleName,EmailID,DOB,MobileNo,CountryID,StateID,CityID,ZipCode,Latitude,Longitude,CreatedOn,LastUpdatedOn,MobileVerifyCode,EmailVerifyCode,IsMobileVerified,IsEmailVerified,IsActive,RecoNumber,RecoExpireDate")] CustomerModel Customermodel, HttpPostedFileBase file) { UserPermissionAction("property", RoleAction.view.ToString()); CheckPermission(); TempData["ShowMessage"] = ""; TempData["MessageBody"] = ""; try { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please fill the required field with valid data"; if (ModelState.IsValid) { var CustomerFound = _CustomerService.GetCustomers().Where(c => ((c.EmailId.Trim() == Customermodel.EmailID.Trim() || c.MobileNo.Trim() == Customermodel.MobileNo.Trim()) && c.CustomerId != Customermodel.CustomerId)).FirstOrDefault(); if (CustomerFound == null) { var PhotoPath = ""; var CustomerUpdate = _CustomerService.GetCustomer(Customermodel.CustomerId);//.Where(c => c.CustomerId == Customermodel.CustomerId).FirstOrDefault(); if (CustomerUpdate != null) { PhotoPath = CustomerUpdate.PhotoPath; if (file != null) { if (CustomerUpdate.PhotoPath != "") { //Delete Old Image string pathDel = Server.MapPath("~/CustomerPhoto"); FileInfo objfile = new FileInfo(pathDel); if (objfile.Exists) //check file exsit or not { objfile.Delete(); } //End :Delete Old Image } //Save the photo in Folder var fileExt = Path.GetExtension(file.FileName); string fileName = Guid.NewGuid() + fileExt; var subPath = Server.MapPath("~/CustomerPhoto"); //Check SubPath Exist or Not if (!Directory.Exists(subPath)) { Directory.CreateDirectory(subPath); } //End : Check SubPath Exist or Not var path = Path.Combine(subPath, fileName); file.SaveAs(path); PhotoPath = CommonCls.GetURL() + "/CustomerPhoto/" + fileName; } CommonClass CommonClass = new CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "update Customer set PhotoPath='" + PhotoPath + "' ,MobileNo='" + Customermodel.MobileNo + "' ,Address='" + Customermodel.Address + "' ,FirstName='" + Customermodel.FirstName + "' "; QStr += " ,LastName='" + Customermodel.LastName + "',MiddleName='" + Customermodel.MiddleName + "' ,EmailId='" + Customermodel.EmailID + "' ,CityID='" + Convert.ToInt32(Customermodel.CityID) + "' ,StateID='" + Convert.ToInt32(Customermodel.StateID) + "' , "; QStr += "IsActive='" + Convert.ToBoolean(Customermodel.IsActive) + "' ,WebsiteUrl='" + Customermodel.WebsiteUrl + "' ,UpdateStatus='" + true + "' Where CustomerId='" + Convert.ToInt32(Customermodel.CustomerId) + "' "; CommonClass.ExecuteNonQuery(QStr); // dt = CommonClass.GetDataSet(QStr).Tables[0]; CustomerUpdate.LastUpdatedOn = DateTime.Now; _CustomerService.UpdateCustomer(CustomerUpdate); if (Customermodel.IsActive == false) { string Flag = "14"; var NotificationStatus = false; string Message = "Your account is deactivated"; string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\"}"; //Save Notification Notification Notification = new Notification(); Notification.NotificationSendBy = 1; Notification.NotificationSendTo = Convert.ToInt32(CustomerUpdate.CustomerId); Notification.IsRead = false; Notification.Flag = Convert.ToInt32(Flag); Notification.RequestMessage = Message; _Notification.InsertNotification(Notification); if (CustomerUpdate.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { CommonCls.SendGCM_Notifications(CustomerUpdate.ApplicationId, JsonMessage, true); } else { //Dictionary<string, object> Dictionary = new Dictionary<string, object>(); //Dictionary.Add("Flag", Flag); //Dictionary.Add("Message", Message); //NotificationStatus = PushNotificatinAlert.SendPushNotification(CustomerUpdate.ApplicationId, Message, Flag.ToString(), JsonMessage, Dictionary, 1); int count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(CustomerUpdate.CustomerId) && c.IsRead == false).ToList().Count(); CommonCls.TestSendFCM_Notifications(CustomerUpdate.ApplicationId, JsonMessage, Message, count, true); } } string FirstName = CustomerUpdate.FirstName + " " + CustomerUpdate.MiddleName + " " + CustomerUpdate.LastName; if (CustomerUpdate.IsUpdated == true) { SendMailToUpdatedUser(FirstName, CustomerUpdate.EmailId, CustomerUpdate.TrebId); } else { SendMailToUser(FirstName, CustomerUpdate.EmailId, CustomerUpdate.TrebId); } TempData["ShowMessage"] = "success"; TempData["MessageBody"] = CustomerUpdate.FirstName + " is update successfully."; } else { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Customer not found."; } return(RedirectToAction("customerlist", "Property")); } else { TempData["ShowMessage"] = "error"; if (CustomerFound.EmailId.Trim() == Customermodel.EmailID.Trim()) { TempData["MessageBody"] = Customermodel.EmailID + " is already exists."; } if (CustomerFound.TrebId.Trim() == Customermodel.TrebId.Trim()) { TempData["MessageBody"] = Customermodel.TrebId + " is already exists."; } if (CustomerFound.MobileNo.Trim() == Customermodel.MobileNo.Trim()) { TempData["MessageBody"] = "This" + " " + Customermodel.MobileNo + " is already exists."; } else { TempData["MessageBody"] = "Please fill the required field with valid data"; } } } } catch (RetryLimitExceededException) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on " + Customermodel.FirstName + " client"; } var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); //ViewBag.CityID = new SelectList(_CityService.GetCities(), "CityID", "CityName", Carriermodel.CityID); // ViewBag.CompanyID = new SelectList(_CompanyService.GetCompanies(), "CompanyID", "CompanyName", Customermodel.CompanyID); //ViewBag.CountryID = new SelectList(_CountryService.GetCountries(), "CountryID", "CountryName", Carriermodel.CountryID); //ViewBag.StateID = new SelectList(_StateService.GetStates(), "StateID", "StateName", Carriermodel.StateID); ViewBag.UserId = new SelectList(_UserService.GetUsers(), "UserId", "FirstName", Customermodel.UserId); ViewBag.CityID = (Customermodel.CityID <= 0 ? "" : Customermodel.CityID.ToString()); ViewBag.StateID = (Customermodel.StateID <= 0 ? "" : Customermodel.StateID.ToString()); ViewBag.Countrylist = new SelectList(_CountryService.GetCountries(), "CountryID", "CountryName", Customermodel.CountryID); ViewBag.Statelist = new SelectList(_StateService.GetStates(), "StateID", "StateName", Customermodel.StateID); ViewBag.Citylist = new SelectList(_CityService.GetCities(), "CityID", "CityName", Customermodel.CityID); return(View(Customermodel)); }
public ActionResult Create(EventModel EventModel, HttpPostedFileBase file) { UserPermissionAction("event", RoleAction.view.ToString()); CheckPermission(); TempData["ShowMessage"] = ""; TempData["MessageBody"] = ""; try { if (ModelState.IsValid) { if (string.IsNullOrEmpty(EventModel.EventDate.ToString())) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please select a valid Event Date."; return(View("Create", EventModel)); } if (string.IsNullOrEmpty(EventModel.EventName)) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please Fill Event Name."; return(View("Create", EventModel)); } if (string.IsNullOrEmpty(EventModel.EventDescription)) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please Fill EventDescription."; return(View("Create", EventModel)); } //CultureInfo culture = new CultureInfo("en-US"); //DateTime TodayDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"), culture); //if (Convert.ToDateTime(EventModel.EventDate.ToString("MM/dd/yyyy"), culture) < TodayDate) //{ // TempData["ShowMessage"] = "error"; // TempData["MessageBody"] = "You cannot add old date event."; // return View("Create", EventModel); //} Mapper.CreateMap <CommunicationApp.Models.EventModel, CommunicationApp.Entity.Event>(); CommunicationApp.Entity.Event Event = Mapper.Map <CommunicationApp.Models.EventModel, CommunicationApp.Entity.Event>(EventModel); string EventImage = ""; if (file != null) { if (Event.EventImage != "") { //Delete Old Image string pathDel = Server.MapPath("~/EventPhoto"); FileInfo objfile = new FileInfo(pathDel); if (objfile.Exists) //check file exsit or not { objfile.Delete(); } //End :Delete Old Image } //Save the photo in Folder var fileExt = Path.GetExtension(file.FileName); string fileName = Guid.NewGuid() + fileExt; var subPath = Server.MapPath("~/EventPhoto"); //Check SubPath Exist or Not if (!Directory.Exists(subPath)) { Directory.CreateDirectory(subPath); } //End : Check SubPath Exist or Not var path = Path.Combine(subPath, fileName); file.SaveAs(path); EventImage = CommonCls.GetURL() + "/EventPhoto/" + fileName; } Event.CustomerId = Convert.ToInt32(Session["CustomerId"]);//CutomerId Event.IsActive = true; Event.CreatedOn = DateTime.Now; Event.EventImage = EventImage; _EventService.InsertEvent(Event); List <int> CustomerIds = new List <int>(); var Customers = new List <Customer>(); try { if (EventModel.All == true) { EventModel.SelectedCustomer = null; Customers = _CustomerService.GetCustomers().ToList(); foreach (var Customer in Customers) { CustomerIds.Add(Convert.ToInt32(Customer.CustomerId)); EventCustomer EventCustomer = new Entity.EventCustomer(); EventCustomer.EventId = Event.EventId; EventCustomer.CustomerId = Customer.CustomerId; _EventCustomerService.InsertEventCustomer(EventCustomer); } } else if (EventModel.SelectedCustomer != null) { foreach (var Customer in EventModel.SelectedCustomer) { CustomerIds.Add(Convert.ToInt32(Customer)); EventCustomer EventCustomer = new Entity.EventCustomer(); EventCustomer.EventId = Event.EventId; EventCustomer.CustomerId = Event.CustomerId; _EventCustomerService.InsertEventCustomer(EventCustomer); } } } catch (Exception ex) { ErrorLogging.LogError(ex); throw; } string Flag = "12";//status for Event; var Message = "New event saved."; //send notification try { var CustomerList = _CustomerService.GetCustomers().Where(c => CustomerIds.Contains(c.CustomerId) && c.CustomerId != EventModel.CustomerId && c.IsActive == true).ToList(); foreach (var Customer in CustomerList) { if (Customer != null) { if (Customer.ApplicationId != null && Customer.ApplicationId != "") { bool NotificationStatus = true; string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\"}"; try { //Save Notification Notification Notification = new Notification(); Notification.NotificationSendBy = 1; Notification.NotificationSendTo = Convert.ToInt32(Customer.CustomerId); Notification.IsRead = false; Notification.Flag = Convert.ToInt32(Flag); Notification.RequestMessage = Message; _Notification.InsertNotification(Notification); if (Customer.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { CommonCls.SendGCM_Notifications(Customer.ApplicationId, JsonMessage, true); } else { int count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(Customer.CustomerId) && c.IsRead == false).ToList().Count(); //Dictionary<string, object> Dictionary = new Dictionary<string, object>(); //Dictionary.Add("Flag", Flag); //Dictionary.Add("Message", Message); //NotificationStatus = PushNotificatinAlert.SendPushNotification(Customer.ApplicationId, Message, Flag, JsonMessage, Dictionary, 1, Convert.ToBoolean(Customer.IsNotificationSoundOn)); CommonCls.TestSendFCM_Notifications(Customer.ApplicationId, JsonMessage, Message, count, true); ////Save Notification //Notification Notification = new Notification(); //Notification.NotificationSendBy = 1; //Notification.NotificationSendTo = Customer.CustomerId; //Notification.IsRead = false; //Notification.RequestMessage = Message; //_Notification.InsertNotification(Notification); } } catch (Exception ex) { CommonCls.ErrorLog(ex.ToString()); } } } } } catch (Exception ex) { ErrorLogging.LogError(ex); throw; } TempData["ShowMessage"] = "success"; TempData["MessageBody"] = "Event successfully saved."; return(RedirectToAction("Index")); } var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); var CustomerList1 = _CustomerService.GetCustomers(); EventModel.CustomersList = CustomerList1.Select(x => new SelectListItem { Value = x.CustomerId.ToString(), Text = x.FirstName }).ToList(); EventModel.CustomerId = 1; return(View(EventModel)); } catch (Exception ex) { ErrorLogging.LogError(ex); return(View(EventModel)); } }
public HttpResponseMessage SaveReviewAndRating([FromBody] ReviewAndRatingModel ReviewAndRatingModel) { try { if (ReviewAndRatingModel.CustomerId == new Guid()) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter)); } if (ReviewAndRatingModel.JobRequestId == 0) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "JobRequest Id is blank"), Configuration.Formatters.JsonFormatter)); } if (ReviewAndRatingModel.Rating == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Rating is blank."), Configuration.Formatters.JsonFormatter)); } //if (ReviewAndRatingModel.Rating > 5) //{ // return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Rating cant be greater than 5."), Configuration.Formatters.JsonFormatter); //} var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == ReviewAndRatingModel.CustomerId && c.IsActive == true).FirstOrDefault(); if (customer != null) { var job = _RequestService.GetRequest(ReviewAndRatingModel.JobRequestId); if (job == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "job not found."), Configuration.Formatters.JsonFormatter)); } if (job.JobStatus != EnumValue.GetEnumDescription(EnumValue.JobStatus.Completed)) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "job is not completed yet."), Configuration.Formatters.JsonFormatter)); } var jobFound = _ReviewAndRatingService.GetReviewAndRatings().Where(f => f.CustomerId == ReviewAndRatingModel.CustomerId && f.JobRequestId == ReviewAndRatingModel.JobRequestId).FirstOrDefault(); if (jobFound == null) { Mapper.CreateMap <ReviewAndRatingModel, ReviewAndRating>(); ReviewAndRating reviewAndRating = Mapper.Map <ReviewAndRatingModel, ReviewAndRating>(ReviewAndRatingModel); _ReviewAndRatingService.InsertReviewAndRating(reviewAndRating); var customerBy = _CustomerService.GetCustomer(ReviewAndRatingModel.CustomerId); string UserMessage = "You have new reviews."; string NotificationType = "reviews"; string Flag = "NewReviews"; //Save notification in Table Notification Notification = new Notification(); Notification.NotificationId = 0; //New Case //Notification.ClientId = _Event.ClientID; Save it as NULL Notification.CustomerIdBy = customerBy.CustomerId; //Notification.CustomerIdTo = customerTo.CustomerId; //Notification.EventID = _Event.EventID; Save it as NULL Notification.UserMessage = UserMessage; Notification.NotificationType = NotificationType; Notification.Flag = Flag; Notification.DeviceType = customerBy.DeviceType; _NotificationService.InsertNotification(Notification); // //End : Save notification in Table string ApplicationId = ""; string DeviceType = ""; if (job.CustomerIdBy == customerBy.CustomerId) { ApplicationId = _CustomerService.GetCustomer(job.CustomerIdTo).ApplicationId; DeviceType = _CustomerService.GetCustomer(job.CustomerIdTo).DeviceType; } else { ApplicationId = _CustomerService.GetCustomer(job.CustomerIdBy).ApplicationId; DeviceType = _CustomerService.GetCustomer(job.CustomerIdBy).DeviceType; } string Message = "{\"flag\":\"" + Flag + "\",\"JobRequestId\":\"" + ReviewAndRatingModel.JobRequestId + "\",\"UserMessage\":\"" + UserMessage + "\"}"; if (ApplicationId != null && ApplicationId != "") { if (DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { //Send Notification another Andriod CommonCls.SendFCM_Notifications(ApplicationId, Message, true); } else { string Msg = UserMessage; CommonCls.TestSendFCM_Notifications(ApplicationId, Message, Msg, true); } } return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Reviews saved successfully."), Configuration.Formatters.JsonFormatter)); } else { jobFound.Rating = (ReviewAndRatingModel.Rating != 0 ? ReviewAndRatingModel.Rating : jobFound.Rating); jobFound.Review = (ReviewAndRatingModel.Review != null && ReviewAndRatingModel.Review != "") ? ReviewAndRatingModel.Review : jobFound.Review; _ReviewAndRatingService.UpdateReviewAndRating(jobFound); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Reviews updated successfully."), Configuration.Formatters.JsonFormatter)); } } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter)); } } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); ErrorLogging.LogError(ex); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter)); } }