public HttpResponseMessage GetChatList([FromBody] ChatModel ChatModel) { var userList = new UserChatModel(); var models = new List <ChatsModel>(); try { int count = 0; List <Guid?> ListCustomerIDs = new List <Guid?>(); ListCustomerIDs.Add(ChatModel.CustomerIdBy); ListCustomerIDs.Add(ChatModel.CustomerIdTo); var Chats = _ChatService.GetAll().Where(x => ListCustomerIDs.Contains(x.CustomerIdBy) && ListCustomerIDs.Contains(x.CustomerIdTo)).ToList(); var Results = (from m in Chats where m.CustomerIdBy == ChatModel.CustomerIdBy && m.CustomerIdTo == ChatModel.CustomerIdTo select m) .Concat(from m in Chats where m.CustomerIdBy == ChatModel.CustomerIdTo && m.CustomerIdTo == ChatModel.CustomerIdBy select m) .OrderBy(x => x.DateTimeCreated); Mapper.CreateMap <HomeHelp.Entity.Chat, HomeHelp.Models.ChatsModel>().ForMember(c => c.CustomersBy, option => option.Ignore()).ForMember(c => c.CustomersTo, option => option.Ignore()); foreach (var Chat in Results) { bool IsSkipRec = false; if (Chat.CustomerIdBy == ChatModel.CustomerIdBy && Convert.ToBoolean(Chat.IsDeletedCustomerBy)) { IsSkipRec = true; } else if (Chat.CustomerIdTo == ChatModel.CustomerIdBy && Convert.ToBoolean(Chat.IsDeletedCustomerTo)) { IsSkipRec = true; } if (!IsSkipRec) { //When Our Customer ID (By) will match with Others CustomerID (To) then Update Read Message status if (Chat.CustomerIdTo == ChatModel.CustomerIdBy) { //Update the Chat For IsRead Field true, It will Update by Trigger in SQL Table _ChatService.Update(new HomeHelp.Entity.Chat { ChatId = Chat.ChatId, CustomerIdBy = Chat.CustomerIdBy, CustomerIdTo = Chat.CustomerIdTo, ChatContent = Chat.ChatContent, DateTimeCreated = Chat.DateTimeCreated, IsDeletedCustomerBy = Chat.IsDeletedCustomerBy, IsDeletedCustomerTo = Chat.IsDeletedCustomerTo, IsRead = true }); //End : Update the Chat For IsRead Field true //Set the Read Message Status for List Chat.IsRead = true; } Models.ChatsModel chatModel = Mapper.Map <HomeHelp.Entity.Chat, HomeHelp.Models.ChatsModel>(Chat); string sqlFormattedDate = Chat.DateTimeCreated.HasValue ? Chat.DateTimeCreated.Value.ToString("yyyy-MM-dd HH:mm:ss.fff") : ""; chatModel.DateTimeCreated = sqlFormattedDate; //chatModel.ChatTime = chatTime(Chat.DateTimeCreated); // chatModel.ChatTime = Convert.ToDateTime(Chat.DateTimeCreated).ToString("hh:mm tt"); //Set Customer By Mapper.CreateMap <HomeHelp.Entity.Customer, HomeHelp.Models.UserCustomerDetailModel>(); HomeHelp.Entity.Customer customersBy = _CustomerService.GetCustomer(Chat.CustomerIdBy); Models.UserCustomerDetailModel customerByModel = Mapper.Map <HomeHelp.Entity.Customer, HomeHelp.Models.UserCustomerDetailModel>(customersBy); //End : Set Customer By chatModel.CustomersBy = customerByModel; //Set Customer To Mapper.CreateMap <HomeHelp.Entity.Customer, HomeHelp.Models.UserCustomerDetailModel>(); HomeHelp.Entity.Customer customersTo = _CustomerService.GetCustomer(Chat.CustomerIdTo); Models.UserCustomerDetailModel customerToModel = Mapper.Map <HomeHelp.Entity.Customer, HomeHelp.Models.UserCustomerDetailModel>(customersTo); //End : Set Customer To chatModel.CustomersTo = customerToModel; count++; models.Add(chatModel); } } int numberOfObjectsPerPage = 10; var modelsdata = models.OrderByDescending(c => c.DateTimeCreated).Skip(numberOfObjectsPerPage * ChatModel.PageNumber).Take(numberOfObjectsPerPage).ToList(); //userList.CountMessage = count; //userList.chatList = modelsdata; return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", modelsdata), Configuration.Formatters.JsonFormatter)); } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); ErrorLogging.LogError(ex); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", models), Configuration.Formatters.JsonFormatter)); } }
public async Task <HttpResponseMessage> UploadImage() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string root = HttpContext.Current.Server.MapPath("~/IdProof/temp"); CustomMultipartFormDataStreamProvider1 provider = new CustomMultipartFormDataStreamProvider1(root); try { StringBuilder sb = new StringBuilder(); // Holds the response body Type type = typeof(CustomerModel); // Get type pointer CustomerModel locationImagesModel = new CustomerModel(); // Read the form data and return an async task. CustomMultipartFormDataStreamProvider1 x = await Request.Content.ReadAsMultipartAsync(provider); Guid CustomerId = new Guid(); // This illustrates how to get the form data. foreach (var key in provider.FormData.AllKeys) { if (key == "CustomerId") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { CustomerId = new Guid(propertyValue); break; } } } //Delete all already exist files HomeHelp.Entity.Customer Customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CustomerId && c.IsActive == true).FirstOrDefault(); if (Customer != null) { if (Customer.IdProof != "" && Customer.IdProof != null) { DeleteImage(Customer.IdProof); } } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No user found."), Configuration.Formatters.JsonFormatter)); } // Process the list of files found in the directory. string[] fileEntries = Directory.GetFiles(root); foreach (string fileName in fileEntries) { var fileFound = provider.FileData.Where(c => c.Headers.ContentDisposition.FileName.Replace("\"", string.Empty) == Path.GetFileName(fileName)).FirstOrDefault(); if (fileFound != null) { //string NewFileName = Guid.NewGuid() + "_Event" + EventId.ToString() + Path.GetExtension(fileName); string NewFileName = Guid.NewGuid() + Path.GetExtension(fileName); string NewRoot = HttpContext.Current.Server.MapPath("~/IdProof") + "\\" + NewFileName; System.IO.File.Move(fileName, NewRoot); string URL = CommonCls.GetURL() + "/IdProof/" + NewFileName; Customer.IdProof = URL; _CustomerService.UpdateCustomer(Customer); sb.Append(URL); } } return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", Customer.IdProof), Configuration.Formatters.JsonFormatter)); } catch (System.Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }
public async Task <HttpResponseMessage> UploadCustomerProfile() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string root = HttpContext.Current.Server.MapPath("~/CustomerPhoto/temp"); CustomMultipartFormDataStreamProvider1 provider = new CustomMultipartFormDataStreamProvider1(root); try { StringBuilder sb = new StringBuilder(); // Holds the response body Type type = typeof(CustomerModel); // Get type pointer CustomerModel locationImagesModel = new CustomerModel(); // Read the form data and return an async task. CustomMultipartFormDataStreamProvider1 x = await Request.Content.ReadAsMultipartAsync(provider); int CustomerId = 0; string Bio = ""; string Privacy = ""; int Age = 0; string Gender = ""; string Music = ""; string Photography = ""; string Camping = ""; string Hiking = ""; // This illustrates how to get the form data. foreach (var key in provider.FormData.AllKeys) { if (key == "CustomerId") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { CustomerId = Convert.ToInt32(propertyValue); if (CustomerId == 0) { return(ErrorMessage("error", "Customer Id is blank.")); } } } if (key == "Age") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Age = Convert.ToInt32(propertyValue); if (Age == 0) { return(ErrorMessage("error", "Age is blank.")); } } } if (key == "Bio") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Bio = propertyValue; if (Bio == "" || Bio == null) { return(ErrorMessage("error", "Bio is blank.")); } } } if (key == "Privacy") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Privacy = propertyValue; if (Privacy != EnumValue.GetEnumDescription(EnumValue.Privacy.Public) && Privacy != EnumValue.GetEnumDescription(EnumValue.Privacy.Private)) { return(ErrorMessage("error", "Privacy is wrong.")); } if (Privacy == "" || Privacy == null) { return(ErrorMessage("error", "Privacy is blank.")); } } } if (key == "Gender") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Gender = propertyValue; if (Gender != EnumValue.GetEnumDescription(EnumValue.Gender.Female) && Gender != EnumValue.GetEnumDescription(EnumValue.Gender.Male)) { return(ErrorMessage("error", "Gender is wrong.")); } if (Gender == "" || Gender == null) { return(ErrorMessage("error", "Gender is blank.")); } } } if (key == "Music") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Music = propertyValue; if (Music == "" || Music == null) { return(ErrorMessage("error", "Music is blank.")); } } } if (key == "Photography") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (Photography != null) { Photography = propertyValue; if (Photography == "" || Photography == null) { return(ErrorMessage("error", "Photography is blank.")); } } } if (key == "Camping") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Camping = propertyValue; if (Camping == "" || Camping == null) { return(ErrorMessage("error", "Camping is blank.")); } } } if (key == "Hiking") { string propertyValue = provider.FormData.GetValues(key).FirstOrDefault(); if (propertyValue != null) { Hiking = propertyValue; if (Hiking == "" || Hiking == null) { return(ErrorMessage("error", "Hiking is blank.")); } } } if (CustomerId != 0 && Bio != "" && Privacy != "" && Age != 0 && Gender != "" && Music != "" && Photography != "" && Camping != "" && Hiking != "") { break; } } //Delete all already exist files HomeHelp.Entity.Customer Customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CustomerId && c.IsActive == true).FirstOrDefault(); if (Customer != null) { if (Customer.PhotoPath != "" && Customer.PhotoPath != null) { DeleteImage(Customer.BackgroundImage); } } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No user found."), Configuration.Formatters.JsonFormatter)); } // Process the list of files found in the directory. string[] fileEntries = Directory.GetFiles(root); foreach (string fileName in fileEntries) { var fileFound = provider.FileData.Where(c => c.Headers.ContentDisposition.FileName.Replace("\"", string.Empty) == Path.GetFileName(fileName)).FirstOrDefault(); if (fileFound != null) { //string NewFileName = Guid.NewGuid() + "_Event" + EventId.ToString() + Path.GetExtension(fileName); string NewFileName = Guid.NewGuid() + Path.GetExtension(fileName); string NewRoot = HttpContext.Current.Server.MapPath("~/CustomerPhoto") + "\\" + NewFileName; System.IO.File.Move(fileName, NewRoot); string URL = CommonCls.GetURL() + "/CustomerPhoto/" + NewFileName; Customer.PhotoPath = URL; sb.Append(URL); } } Customer.Bio = Bio; Customer.Privacy = Privacy; Customer.Age = Age; Customer.Gender = Gender; _CustomerService.UpdateCustomer(Customer); HobbiesAndInterests hobbies = _HobbiesAndInterestsService.GetHobbiesAndInterestss().Where(c => c.CustomerId == CustomerId).FirstOrDefault(); if (hobbies != null) { hobbies.Music = Convert.ToInt32(Music); hobbies.Hiking = Convert.ToInt32(Hiking); hobbies.Camping = Convert.ToInt32(Camping); hobbies.Photography = Convert.ToInt32(Photography); hobbies.CustomerId = CustomerId; _HobbiesAndInterestsService.UpdateHobbiesAndInterests(hobbies); } else { HobbiesAndInterests objHobbies = new HobbiesAndInterests(); objHobbies.Music = Convert.ToInt32(Music); objHobbies.Hiking = Convert.ToInt32(Hiking); objHobbies.Camping = Convert.ToInt32(Camping); objHobbies.Photography = Convert.ToInt32(Photography); objHobbies.CustomerId = CustomerId; _HobbiesAndInterestsService.InsertHobbiesAndInterests(objHobbies); } Mapper.CreateMap <Customer, UserCustomerModel>(); UserCustomerModel userCustomerModel = Mapper.Map <Customer, UserCustomerModel>(Customer); userCustomerModel.Music = Music; userCustomerModel.Hiking = Hiking; userCustomerModel.Camping = Camping; userCustomerModel.Photography = Photography; return(ErrorMessage("success", userCustomerModel)); } catch (System.Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }