public IHttpActionResult delete(int id) { int user_id = Users.GetUserId(User); Advert advert = db.advert.Where(a => a.id == id && a.user_id == user_id).FirstOrDefault(); if (advert == null) { return(NotFound()); } db.advert.Remove(advert); //Unavaiable Dates db.advert_unavaiable_dates.RemoveRange(db.advert_unavaiable_dates.Where(uad => uad.advert_id == id)); //Avaiable Dates db.advert_avaiable_dates.RemoveRange(db.advert_avaiable_dates.Where(ad => ad.advert_id == id)); try { db.SaveChanges(); } catch (System.Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult forgotpas([FromBody] _Mail mail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Users user = db.users.Where(u => u.email == mail.email).FirstOrDefault(); if (user == null) { return(NotFound()); } //generate password reset token Random rnd = new Random(); string token = Bcrypt.hash(user.email + DateTime.Now.Hour + DateTime.Now.Millisecond + rnd.Next(999999, 999999)); try { user.forgot_last_date = DateTime.Now; user.password_token = token; db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } Mailgun.Send("forgot_password", new Dictionary <string, object>() { { "fullname", user.name + " " + user.lastname }, { "token", token } }, user.email, "Menkule Şifre Yenileme Talebiniz"); return(Ok()); }
public IHttpActionResult add([FromBody] AdvertScores advertScore) { int user_id = Users.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!db.advert.Any(a => a.id == advertScore.advert_id)) { return(NotFound()); } db.advert_scores.Add(advertScore); try { db.SaveChanges(); } catch (System.Exception ex) { ExceptionThrow.Throw(ex); } return(Ok(advertScore)); }
public IHttpActionResult update([FromBody] AdvertComments advertComments, int id) { int user_id = Users.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!db.advert_comments.Any(ac => ac.advert_id == advertComments.advert_id && ac.id == id && ac.user_id == user_id)) { return(NotFound()); } using (var dbContext = new DatabaseContext()) { advertComments.id = id; advertComments.user_id = user_id; advertComments.updated_date = DateTime.Now; dbContext.Entry(advertComments).State = System.Data.Entity.EntityState.Modified; try { dbContext.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } } return(Ok(advertComments)); }
public IHttpActionResult add([FromBody] AdvertComments advertComments) { int user_id = Users.GetUserId(User); Users user = db.users.Find(user_id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!db.advert.Any(a => a.id == advertComments.advert_id)) { return(NotFound()); } advertComments.user_id = user_id; db.advert_comments.Add(advertComments); try { db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok(advertComments)); }
public IHttpActionResult changepas([FromBody] _UserPassword password) { if (password.password != password.reply) { return(BadRequest()); } int user_id = Users.GetUserId(User); string pas = Bcrypt.hash(password.currentpassword); Users user = db.users.Where(u => u.id == user_id && u.password == pas).FirstOrDefault(); if (user == null) { return(NotFound()); } user.password = Bcrypt.hash(password.password); try { db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult add([FromBody] AdvertFeedbacks advertFeedbacks) { int user_id = Users.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!db.advert.Any(a => a.id == advertFeedbacks.advert_id)) { return(NotFound()); } advertFeedbacks.user_id = user_id; if (db.advert_feedbakcs.Where(af => af.advert_id == advertFeedbacks.advert_id & af.user_id == user_id).ToList().Count == 5) { ExceptionThrow.Throw("Bir ilan için en fazla 5 kere geri bildirim hakkınız bulunmaktadır.", System.Net.HttpStatusCode.Forbidden); } db.advert_feedbakcs.Add(advertFeedbacks); try { db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok(advertFeedbacks)); }
public IHttpActionResult mail() { int user_id = Users.GetUserId(User); if (!db.users.Any(u => u.email_state == true && u.id == user_id)) { ExceptionThrow.Throw("E-posta adresi onaylanmadı.", HttpStatusCode.Forbidden); } return(Ok()); }
public IHttpActionResult gsm() { int user_id = Users.GetUserId(User); if (!db.users.Any(u => u.gsm_state == true && u.id == user_id)) { ExceptionThrow.Throw("Gsm no onaylanmadı.", HttpStatusCode.Forbidden); } return(Ok()); }
public IHttpActionResult send([FromBody] _Contact message) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!MailSender.Send(message)) { ExceptionThrow.Throw("Mesajınız iletilemedi. Lütfen tekrar deneyin."); } return(Ok()); }
public IHttpActionResult resendGsmCode() { int user_id = Users.GetUserId(User); Users user = db.users.Where(u => u.id == user_id).FirstOrDefault(); if (user == null) { return(NotFound()); } if (String.IsNullOrEmpty(user.gsm)) { ExceptionThrow.Throw("Lütfen geçerli bir gsm numarası kullanın.", HttpStatusCode.BadRequest); } if (user.gsm_last_update != null) { TimeSpan diff = DateTime.Now - Convert.ToDateTime(user.gsm_last_update); if (diff.TotalMinutes <= 4) { ExceptionThrow.Throw("Yeni aktivasyon kodu için 4 dakika beklemeniz gerekmektedir.", HttpStatusCode.Forbidden); } } //generate activation code Random rnd = new Random(); string gsm_code = rnd.Next(9999, 999999).ToString(); try { user.gsm_activation_code = gsm_code; user.gsm_last_update = DateTime.Now; db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } //Send Gsm Activation Code NetGsm.Send(user.gsm, "menkule.com.tr uyeliginiz ile ilgili onay kodunuz: " + user.gsm_activation_code); return(Ok()); }
public IHttpActionResult delete(int id) { int user_id = Users.GetUserId(User); AdvertComments comment = db.advert_comments.Where(ac => ac.id == id).FirstOrDefault(); if (comment == null) { return(NotFound()); } db.advert_comments.Remove(comment); try { db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult delete(int id) { int user_id = Users.GetUserId(User); try { Notifications notify = db.notifications.Where(n => n.user_id == user_id && n.id == id).FirstOrDefault(); if (notify == null) { return(NotFound()); } db.notifications.Remove(notify); db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult resetpas([FromBody] _TokenResetPassword _token) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_token.password != _token.reply) { return(BadRequest()); } Users user = db.users.Where(u => u.password_token == _token.token).FirstOrDefault(); if (user == null) { return(NotFound()); } if (user.forgot_last_date != null) { TimeSpan diff = DateTime.Now - Convert.ToDateTime(user.forgot_last_date); if (diff.TotalHours >= 2) { return(BadRequest()); } } try { user.password = Bcrypt.hash(_token.password); user.forgot_last_date = null; user.password_token = null; db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult approveMail([FromBody] _Code userApproved) { int user_id = Users.GetUserId(User); Users user = db.users.Where(u => u.id == user_id && u.email_activation_code == userApproved.code).FirstOrDefault(); if (user == null) { return(NotFound()); } user.email_state = true; try { //db.SaveChanges(); } catch (Exception e) { ExceptionThrow.Throw(e); } return(Ok()); }
public IHttpActionResult add([FromBody] Suggetions suggestions) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (db.suggestions.Any(s => s.email == suggestions.email)) { return(BadRequest()); } db.suggestions.Add(suggestions); try { db.SaveChanges(); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult ownerApprove() { int user_id = Users.GetUserId(User); Users user = db.users.Find(user_id); if (user == null) { return(NotFound()); } user.ownershiping = true; try { db.SaveChanges(); } catch (Exception e) { ExceptionThrow.Throw(e); } return(Ok()); }
public IHttpActionResult externalConfirm([FromBody] _ExternalConfirm externalConfirmData) { int user_id = Users.GetUserId(User); if (externalConfirmData.password != externalConfirmData.reply) { ExceptionThrow.Throw("Şifre tekrarı hatalı.", HttpStatusCode.BadRequest); } if (db.users.Any(u => u.gsm == externalConfirmData.gsm)) { ExceptionThrow.Throw("gsm no kullanılmaktadır.", HttpStatusCode.BadRequest); } Users user = db.users.Where(u => u.id == user_id && u.is_external_confirm == false).FirstOrDefault(); if (user == null) { ExceptionThrow.Throw("Zaten şifre güncellenmiş", HttpStatusCode.Forbidden); } user.gsm = externalConfirmData.gsm; user.updated_date = DateTime.Now; user.password = Bcrypt.hash(externalConfirmData.password); user.is_external_confirm = true; try { db.SaveChanges(); //Send Gsm Activation Code NetGsm.Send(externalConfirmData.gsm, "menkule.com.tr uyeliginiz ile ilgili onay kodunuz: " + user.gsm_activation_code); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok()); }
public IHttpActionResult add([FromBody] Advert advert) { int user_id = Users.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Advert Images Validation var imagesList = advert.images.ToList(); if (imagesList.FindAll(img => !img.deleted).Count > 20) { ExceptionThrow.Throw("Maksimum fotoğraf limitini aştınız.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => img.is_default && !img.deleted).Count == 0) { ExceptionThrow.Throw("Varsayılan fotoğraf seçin.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => !img.deleted).Count < 3) { ExceptionThrow.Throw("En az 3 fotoğraf yüklemelisiniz.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => img.is_default).Count > 1) { ExceptionThrow.Throw("En fazla 1 fotoğraf varsayılan olarak seçilebilir.", System.Net.HttpStatusCode.BadRequest); } advert.user_id = user_id; advert.score = 0; advert.state = false; advert.views = 0; advert.created_date = DateTime.Now; advert.updated_date = null; db.advert.Add(advert); db.SaveChanges(); List <_AdvertImages> selectedImages = advert.images.ToList().FindAll(i => i.is_default == true); if (selectedImages.Count == 0) { advert.images.ToList()[0].is_default = true; } if (selectedImages.Count > 1) { advert.images.ToList().ForEach(i => i.is_default = false); advert.images.ToList()[0].is_default = true; } // Images advert.images.ToList().ForEach(i => { if (i.is_new) { AdvertImages ai = new AdvertImages() { advert_id = advert.id, image_id = i.id, is_default = i.is_default }; db.advert_images.Add(ai); } }); //Possibility advert.possibility.advert_id = advert.id; db.advert_possibilities.Add(advert.possibility); //Properties advert.properties.advert_id = advert.id; db.advert_properties.Add(advert.properties); //Unavaiable Dates if (advert.unavaiable_date != null) { advert.unavaiable_date.ToList().ForEach(i => { i.advert_id = advert.id; db.advert_unavaiable_dates.Add(i); }); } //Avaiable Dates if (advert.available_date != null) { advert.available_date.ToList().ForEach(ad => { for (DateTime date = ad.from_fulldate; date.Date <= ad.to_fulldate.Date; date = date.AddDays(1)) { AdvertAvailableDate avaiableDate = new AdvertAvailableDate() { day = date.Day, month = date.Month, year = date.Year, fulldate = date, uniq = String.Format("{0:MMddyyyy}", ad.from_fulldate) + String.Format("{0:MMddyyyy}", ad.to_fulldate), advert_id = advert.id }; db.advert_avaiable_dates.Add(avaiableDate); } }); } try { db.SaveChanges(); } catch (System.Exception ex) { ExceptionThrow.Throw(ex); } return(Ok(advert)); }
public IHttpActionResult cancel(int id) { int user_id = Users.GetUserId(User); Rezervations rezervation = db.rezervations.Find(id); if (rezervation == null) { return(NotFound()); } if (rezervation.is_cancel) { ExceptionThrow.Throw("Rezervasyon daha önce iptal edilmiş.", HttpStatusCode.Forbidden); } RezervationAdverts advert = db.rezervation_adverts.Where(ra => ra.advert_id == rezervation.advert_id).FirstOrDefault(); if (advert == null) { return(NotFound()); } bool is_cancel = rezervation.is_cancel; rezervation.state = false; rezervation.is_cancel = true; rezervation.updated_date = DateTime.Now; if (advert.user_id == user_id) { Users user = db.users.Find(rezervation.user_id); if (user == null) { return(NotFound()); } db.SaveChanges(); // Add notify Notifications notify = new Notifications(); notify.add(user.id, "#" + rezervation.id + " nolu " + rezervation.days + " günlük rezervasyon talebi iptal edildi!", rezervation.id); // Send sms NetGsm.Send(user.gsm, "#" + rezervation.id + " nolu " + "(" + rezervation.days + " gün - " + rezervation.total_price + " TL) rezervasyonunuz iptal edildi. - Menkule.com.tr"); // Send email Mailgun.Send("cancel", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.lastname) }, { "rezervation_id", rezervation.id }, { "checkin", Convert.ToDateTime(rezervation.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rezervation.checkout).ToShortDateString() }, { "days", rezervation.days }, { "price", rezervation.total_price + " TL." } }, user.email, "Rezervasyon talebi iptal edildi."); } // Delete unavaiable dates db.advert_unavaiable_dates.RemoveRange(db.advert_unavaiable_dates.Where(uad => uad.advert_id == rezervation.advert_id && uad.rezervation_id == id)); if (user_id == rezervation.user_id) { DateTime lastCanceleableDate = rezervation.checkin.AddDays(-advert.cancel_time); DateTime EndDate = DateTime.Now; int dateDiff = Convert.ToInt32(lastCanceleableDate.Subtract(EndDate).TotalDays) + 1; if (!(dateDiff <= 0 || is_cancel ? false : true)) { ExceptionThrow.Throw("Bu rezervasyon iptal süresi dışındadır.", HttpStatusCode.Forbidden); } db.SaveChanges(); Users advert_owner = db.users.Find(rezervation.owner); if (advert_owner != null) { // Send sms NetGsm.Send(advert_owner.gsm, "#" + rezervation.id + " nolu " + "(" + rezervation.days + " gün - " + rezervation.total_price + " TL) rezervasyon talebi iptal edildi. - Menkule.com.tr"); // Add Notify Notifications notify = new Notifications(); notify.add(advert_owner.id, "#" + rezervation.id + " nolu " + rezervation.days + " günlük rezervasyon talebi iptal edildi!", rezervation.id); // Send email Mailgun.Send("cancel", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(advert_owner.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(advert_owner.lastname) }, { "rezervation_id", rezervation.id }, { "checkin", Convert.ToDateTime(rezervation.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rezervation.checkout).ToShortDateString() }, { "days", rezervation.days }, { "price", rezervation.total_price + " TL." } }, advert_owner.email, "Rezervasyon talebi iptal edildi."); } } return(Ok()); }
public object forceApprove([FromBody] _ExistRezervation rezervations, int id) { int user_id = Users.GetUserId(User); // get exist rezervation id List <int> rezervations_id = new List <int>(); rezervations.rezervations.ToList().ForEach(r => { if (!db.rezervations.Any(rr => rr.owner == user_id)) { ExceptionThrow.Throw("Yetkisiz işlem gerçekleştirildi!", HttpStatusCode.Forbidden); } rezervations_id.Add(r.id); }); // rezervation validation Rezervations rezervation = db.rezervations.Find(id); if (rezervation == null) { return(NotFound()); } // rezervation validation if (rezervation.updated_date != null) { ExceptionThrow.Throw("Yetkisiz işlem gerçekleştirildi!", HttpStatusCode.Forbidden); } // rezervation advert validation RezervationAdverts advert = db.rezervation_adverts.Where(ra => ra.advert_id == rezervation.advert_id).FirstOrDefault(); if (advert == null) { return(NotFound()); } // rezervation owner validation if (advert.user_id != user_id) { ExceptionThrow.Throw("Yetkisiz işlem gerçekleştirildi!", HttpStatusCode.Forbidden); } // rezervation user validation Users user = db.users.Find(rezervation.user_id); if (user == null) { return(NotFound()); } rezervation.state = true; rezervation.is_cancel = false; rezervation.updated_date = DateTime.Now; // available date validation var dateList = new List <DateTime>(); for (DateTime date = rezervation.checkin; date.Date < rezervation.checkout.Date; date = date.AddDays(1)) { dateList.Add(date); } // set unavaiable date dateList.ForEach(date => { AdvertUnavailableDate advertUnavaiableDate = new AdvertUnavailableDate { advert_id = rezervation.advert_id, day = date.Day, month = date.Month, year = date.Year, fulldate = date, created_date = DateTime.Now, rezervation_id = rezervation.id }; db.advert_unavaiable_dates.Add(advertUnavaiableDate); }); db.rezervations.Where(r => r.owner == user_id && rezervations_id.Contains(r.id)).ToList().ForEach(rez => { rez.state = false; rez.is_cancel = true; rez.updated_date = DateTime.Now; }); db.SaveChanges(); rezervations.rezervations.ForEach(r => { Rezervations rez_ = db.rezervations.Where(r_ => r_.id == r.id && r_.state == false & r_.is_cancel == true).FirstOrDefault(); if (rez_ != null) { Users user_ = db.users.Where(u => u.id == rez_.user_id).FirstOrDefault(); if (user_ != null) { // Add notify Notifications notify_ = new Notifications(); notify_.add(user_.id, "#" + rez_.id + " nolu " + rez_.days + " günlük rezervasyon talebi iptal edildi!", rez_.id); // Send sms NetGsm.Send(user_.gsm, "#" + rez_.id + " nolu " + "(" + rez_.days + " gün - " + rez_.total_price + " TL) rezervasyonunuz iptal edildi. - Menkule.com.tr"); // Send email Mailgun.Send("cancel", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user_.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user_.lastname) }, { "rezervation_id", rez_.id }, { "checkin", Convert.ToDateTime(rez_.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rez_.checkout).ToShortDateString() }, { "days", rez_.days }, { "price", rez_.total_price + " TL." } }, user_.email, "Rezervasyon talebi iptal edildi."); } } }); // send sms NetGsm.Send(user.gsm, "#" + rezervation.id + " nolu " + "(" + rezervation.days + " gün - " + rezervation.total_price + " TL) rezervasyonunuz onaylandı. - Menkule.com.tr"); // send notifications Notifications notify = new Notifications(); notify.add(user.id, "#" + rezervation.id + " nolu rezervasyon talebiniz onaylandı.", rezervation.id); // Send email Mailgun.Send("approve", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.lastname) }, { "rezervation_id", rezervation.id }, { "checkin", Convert.ToDateTime(rezervation.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rezervation.checkout).ToShortDateString() }, { "days", rezervation.days }, { "price", rezervation.total_price + " TL." } }, user.email, "Rezervasyon talebi onaylandı."); return(Ok()); }
public object approve(int id) { int user_id = Users.GetUserId(User); Rezervations rezervation = db.rezervations.Find(id); if (rezervation == null) { return(NotFound()); } if (rezervation.updated_date != null) { ExceptionThrow.Throw("Yetkisiz işlem gerçekleştirildi!", HttpStatusCode.Forbidden); } RezervationAdverts advert = db.rezervation_adverts.Where(ra => ra.advert_id == rezervation.advert_id).FirstOrDefault(); if (advert == null) { return(NotFound()); } if (advert.user_id != user_id) { ExceptionThrow.Throw("Yetkisiz işlem gerçekleştirildi!", HttpStatusCode.Forbidden); } Users user = db.users.Find(rezervation.user_id); if (user == null) { return(NotFound()); } // exist rezervation validations DateTime checkoutDate = rezervation.checkout.AddDays(-1); var exist_rezervations = db.rezervations.Where(r => ((r.checkin >= rezervation.checkin && r.checkin <= checkoutDate) || (r.checkin <= rezervation.checkin && r.checkout <= checkoutDate)) && r.advert_id == advert.advert_id && r.id != id && r.state == false && r.is_cancel == false && r.checkout > rezervation.checkin).ToList(); if (exist_rezervations.Count > 0) { ExceptionThrow.Throw(exist_rezervations, HttpStatusCode.NotImplemented); } rezervation.state = true; rezervation.is_cancel = false; rezervation.updated_date = DateTime.Now; // available date validation var dateList = new List <DateTime>(); for (DateTime date = rezervation.checkin; date.Date < rezervation.checkout.Date; date = date.AddDays(1)) { dateList.Add(date); } // set unavaiable date dateList.ForEach(date => { AdvertUnavailableDate advertUnavaiableDate = new AdvertUnavailableDate { advert_id = rezervation.advert_id, day = date.Day, month = date.Month, year = date.Year, fulldate = date, created_date = DateTime.Now, rezervation_id = rezervation.id }; db.advert_unavaiable_dates.Add(advertUnavaiableDate); }); db.SaveChanges(); // send sms NetGsm.Send(user.gsm, "#" + rezervation.id + " nolu " + "(" + rezervation.days + " gün - " + rezervation.total_price + " TL) rezervasyonunuz onaylandı. - Menkule.com.tr"); // send notifications Notifications notify = new Notifications(); notify.add(user.id, "#" + rezervation.id + " nolu rezervasyon talebiniz onaylandı.", rezervation.id); // Send email Mailgun.Send("approve", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.lastname) }, { "rezervation_id", rezervation.id }, { "checkin", Convert.ToDateTime(rezervation.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rezervation.checkout).ToShortDateString() }, { "days", rezervation.days }, { "price", rezervation.total_price + " TL." } }, user.email, "Rezervasyon talebi onaylandı."); return(Ok()); }
public IHttpActionResult add([FromBody] _Rezervation _rezervation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // get user int user_id = Users.GetUserId(User); Users user = db.users.Where(u => u.id == user_id && u.state == true).FirstOrDefault(); if (user == null) { ExceptionThrow.Throw("Lütfen hesabınızı doğrulayın.", HttpStatusCode.Forbidden); } // existence Advert advert = db.advert.Where(a => a.state == true && a.id == _rezervation.advert_id).FirstOrDefault(); if (advert == null) { return(NotFound()); } if (db.rezervations.Any(rez => rez.user_id == user_id && rez.advert_id == _rezervation.advert_id && rez.checkin == _rezervation.checkin && rez.checkout == _rezervation.checkout)) { ExceptionThrow.Throw("Zaten aynı tarih için bir rezervasyon talebiniz bulunmakta.", HttpStatusCode.Forbidden); } if (user_id == advert.user_id) { ExceptionThrow.Throw("Lütfen farklı bir hesap ile deneyin.", HttpStatusCode.Forbidden); } // visitor validation AdvertProperties properties = db.advert_properties.Where(ap => ap.advert_id == advert.id).FirstOrDefault(); if (properties == null) { return(NotFound()); } if (properties.visitor < _rezervation.visitors.Count) { ExceptionThrow.Throw("Bu ilan için en fazla. " + properties.visitor + " misafir kabul edilebilmektedir.", HttpStatusCode.Forbidden); } // get owner Users owner = db.users.Where(u => u.id == advert.user_id).FirstOrDefault(); if (owner == null) { return(NotFound()); } // rezervation dates list var RezervationDates = new List <DateTime>(); for (DateTime date = _rezervation.checkin; date.Date < _rezervation.checkout.Date; date = date.AddDays(1)) { RezervationDates.Add(date); } // available dates validation List <AdvertAvailableDate> avaiableDates = db.advert_avaiable_dates.Where(aad => aad.advert_id == _rezervation.advert_id).ToList(); if (avaiableDates.Count > 0) { RezervationDates.ForEach(rd => { if (avaiableDates.Find(a => a.fulldate == rd) == null) { ExceptionThrow.Throw("İlan belirtilen tarih için müsait değil.", HttpStatusCode.Forbidden); } }); } // unavailable dates validation if (db.advert_unavaiable_dates.Where(i => i.advert_id == _rezervation.advert_id && RezervationDates.Contains(i.fulldate)).Count() > 0) { ExceptionThrow.Throw("İlan belirtilen tarih için müsait değil.", HttpStatusCode.Forbidden); } // min layover date validation if ((_rezervation.checkout - _rezervation.checkin).TotalDays < advert.min_layover) { ExceptionThrow.Throw("Bu ilan için en az " + advert.min_layover + " günlük rezervasyon oluşturulabilir.", HttpStatusCode.Forbidden); } // create rezervation Rezervations rezervation = new Rezervations { advert_id = _rezervation.advert_id, checkin = _rezervation.checkin, checkout = _rezervation.checkout, created_date = DateTime.Now, gsm = user.gsm, name = user.name, lastname = user.lastname, visitor = _rezervation.visitors.Count, user_id = user.id, day_price = advert.price, owner = advert.user_id, note = _rezervation.note }; db.rezervations.Add(rezervation); db.SaveChanges(); // create rezervations advert RezervationAdverts rezervation_advert = new RezervationAdverts { adress = advert.adress, advert_id = advert.id, cancel_time = advert.cancel_time, city_id = advert.city_id, town_id = advert.town_id, title = advert.title, description = advert.description, entry_time = advert.entry_time, exit_time = advert.exit_time, latitude = advert.latitude, longitude = advert.longitude, rezervation_id = rezervation.id, created_date = advert.created_date, user_id = advert.user_id, advert_type_id = advert.advert_type_id }; db.rezervation_adverts.Add(rezervation_advert); // create visitors _rezervation.visitors.ToList().ForEach(v => { RezervationVisitors visitor = new RezervationVisitors { created_date = DateTime.Now, fullname = v.fullname, gender = v.gender, rezervation_id = rezervation.id, tc = v.tc }; db.rezervation_visitors.Add(visitor); }); db.SaveChanges(); // send notifications Notifications notify = new Notifications(); notify.add(advert.user_id, "#" + advert.id + " nolu ilanınız için " + rezervation.days + " günlük rezervasyon talebi!", rezervation.id); // send sms NetGsm.Send(owner.gsm, "#" + advert.id + " nolu ilaniniz icin toplam " + rezervation.days + " günlük (" + rezervation.total_price + " TL) rezervasyon talebi oluşturuldu. - Menkule.com.tr"); //send mail Mailgun.Send("rezervation", new Dictionary <string, object>() { { "fullname", System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.name) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.lastname) }, { "advert_id", advert.id }, { "checkin", Convert.ToDateTime(rezervation.checkin).ToShortDateString() }, { "checkout", Convert.ToDateTime(rezervation.checkout).ToShortDateString() }, { "days", rezervation.days }, { "price", rezervation.total_price + " TL." } }, owner.email, "Yeni rezervasyon talebi"); return(Ok()); }
public object get(int id) { try { int user_id = Users.GetUserId(User); var rezervation = ( from r in db.rezervations where r.owner == user_id || r.user_id == user_id where r.id == id join ra in db.rezervation_adverts on r.id equals ra.rezervation_id join c in db.cities on ra.city_id equals c.id join t in db.towns on ra.town_id equals t.id join p in db.advert_properties on r.advert_id equals p.advert_id join pos in db.advert_possibilities on r.advert_id equals pos.advert_id join at in db.advert_types on ra.advert_type_id equals at.id select new _RezervationDetails { id = r.id, checkin = r.checkin, checkout = r.checkout, advert_id = r.advert_id, days = r.days, day_price = r.day_price, total_price = r.total_price, user_id = r.user_id, visitor = r.visitor, description_state = r.description_state, note = r.note, is_cancel = r.is_cancel, state = r.state, created_date = r.created_date, updated_date = r.updated_date, rezervation_advert = new _RezervationAdvert { advert = ra, images = (db.advert_images.GroupJoin( db.images, aimg => aimg.image_id, i => i.id, (ai, i) => new { advertimg = ai, image = i } ) .Where(aimg => aimg.advertimg.advert_id == ra.advert_id) .SelectMany(AdvertWithImage => AdvertWithImage.image).ToList()), advert_type = at, cities = c, possibilities = pos, properties = p, towns = t }, visitors = (db.rezervation_visitors.Where(v => v.rezervation_id == r.id)).ToList() } ).FirstOrDefault(); // user informations validation int _user_id = user_id == rezervation.rezervation_advert.advert.user_id ? rezervation.user_id : rezervation.rezervation_advert.advert.user_id; rezervation.advert_owner = rezervation.rezervation_advert.advert.user_id == user_id ? true : false; var user = ( from u in db.users where u.id == _user_id join uimg in db.images on u.image_id equals uimg.id into j1 from j2 in j1.DefaultIfEmpty() select new _RezervationUserInfo { id = u.id, fullname = u.name + " " + u.lastname, gsm = u.gsm, photo = j2.url, identity_no = u.identity_no, gender = u.gender }).FirstOrDefault(); rezervation.user_information = user; if (rezervation.state == false) { rezervation.user_information.gsm = rezervation.user_information.gsm.Substring(0, rezervation.user_information.gsm.Length - 4) + "****"; } // rezervation is cancalable if (!rezervation.advert_owner) { DateTime lastCanceleableDate = rezervation.checkin.AddDays(-rezervation.rezervation_advert.advert.cancel_time); DateTime EndDate = DateTime.Now; int dateDiff = Convert.ToInt32(lastCanceleableDate.Subtract(EndDate).TotalDays) + 1; rezervation.is_cancelable = dateDiff <= 0 || rezervation.is_cancel ? false : true; } // set state notification Notifications notifiy = db.notifications.Where(n => n.user_id == user_id & n.rezervation_id == id).FirstOrDefault(); if (notifiy != null) { notifiy.state = false; db.SaveChanges(); } return(rezervation); } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(NotFound()); }
public IHttpActionResult add([FromBody] Users user) { //validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (db.users.Any(u => u.email == user.email)) { ExceptionThrow.Throw("e-posta adresi kullanılmaktadır.", HttpStatusCode.BadRequest); } if (db.users.Any(u => u.gsm == user.gsm)) { ExceptionThrow.Throw("gsm no kullanılmaktadır.", HttpStatusCode.BadRequest); } //generate activation code Random rnd = new Random(); string gsm_code = rnd.Next(9999, 999999).ToString(); string email_code = rnd.Next(9999, 999999).ToString(); //set password bool no_password = user.password == null || user.password.Trim() == ""; string password = no_password ? Users.generatePassword(5, 3) : user.password; //create user Users userData = new Users { name = user.name, lastname = user.lastname, email = user.email, gender = user.gender, gsm = user.gsm, description = user.description, password = Bcrypt.hash(password), source = "web", email_activation_code = email_code, gsm_activation_code = gsm_code }; if (user.identity_no != null) { userData.identity_no = user.identity_no; } //insert user db.users.Add(userData); try { db.SaveChanges(); //If password is random generated if (no_password) { NetGsm.Send(user.gsm, "Menkule.com.tr üyelik şifreniz " + password + " Şifrenizi değiştirmeyi unutmayınız."); } } catch (Exception ex) { ExceptionThrow.Throw(ex); } //Send Gsm Activation Code NetGsm.Send(user.gsm, "menkule.com.tr uyeliginiz ile ilgili onay kodunuz: " + gsm_code); //Send Email Notification Mailgun.Send("register", new Dictionary <string, object>() { { "fullname", user.name + " " + user.lastname } }, user.email, "Üyeliğiniz için teşekkürler"); object token = no_password ? Users.LoginOnBackDoor(user.email, password) : null; return(Ok(new { name = user.name, lastname = user.lastname, email = user.email, gsm = user.gsm, gender = user.gender, photo = "", ownershiping = user.ownershiping, state = user.state, email_state = user.email_state, gsm_state = user.gsm_state, created_date = user.created_date, token = token })); }
public IHttpActionResult update([FromBody] Advert advert, int id) { int user_id = Users.GetUserId(User); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Advert Images Validation var imagesList = advert.images.ToList(); if (imagesList.FindAll(img => !img.deleted).Count > 20) { ExceptionThrow.Throw("Maksimum fotoğraf limitini aştınız.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => img.is_default && !img.deleted).Count == 0) { ExceptionThrow.Throw("Varsayılan fotoğraf seçin.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => !img.deleted).Count < 3) { ExceptionThrow.Throw("En az 3 fotoğraf yüklemelisiniz.", System.Net.HttpStatusCode.BadRequest); } if (imagesList.FindAll(img => img.is_default).Count > 1) { ExceptionThrow.Throw("En fazla 1 fotoğraf varsayılan olarak seçilebilir.", System.Net.HttpStatusCode.BadRequest); } if (db.advert.Where(a => a.id == id && a.user_id == user_id).FirstOrDefault() == null) { return(NotFound()); } db.Entry(advert).State = System.Data.Entity.EntityState.Detached; AdvertPossibilities apos = db.advert_possibilities.Where(aposs => aposs.advert_id == id).First(); db.Entry(advert.possibility).State = System.Data.Entity.EntityState.Detached; AdvertProperties ap = db.advert_properties.Where(app => app.advert_id == id).First(); db.Entry(advert.properties).State = System.Data.Entity.EntityState.Detached; db.advert_avaiable_dates.RemoveRange(db.advert_avaiable_dates.Where(ad => ad.advert_id == id)); db.advert_unavaiable_dates.RemoveRange(db.advert_unavaiable_dates.Where(ud => ud.advert_id == id)); //Images imagesList.ForEach(i => { if (i.is_new && !db.advert_images.Any(ai => ai.advert_id == id && ai.image_id == i.id)) { AdvertImages ai = new AdvertImages() { advert_id = id, image_id = i.id, is_default = i.is_default }; db.advert_images.Add(ai); } if (i.is_default) { AdvertImages defaultImage = db.advert_images.Where(img => img.image_id == i.id && img.advert_id == id).FirstOrDefault(); if (defaultImage != null) { db.advert_images.Where(ai => ai.advert_id == id).ToList().ForEach(ai => ai.is_default = false); defaultImage.is_default = true; } } if (i.deleted) { AdvertImages deletedImage = db.advert_images.Where(img => img.image_id == i.id && img.advert_id == id).FirstOrDefault(); if (deletedImage != null) { db.advert_images.Remove(deletedImage); } } }); db.SaveChanges(); using (var dbContext = new DatabaseContext()) { //Advert advert.id = id; advert.user_id = user_id; advert.updated_date = DateTime.Now; advert.state = false; dbContext.Entry(advert).State = System.Data.Entity.EntityState.Modified; dbContext.Entry(advert).Property("score").IsModified = false; dbContext.Entry(advert).Property("views").IsModified = false; dbContext.Entry(advert).Property("user_id").IsModified = false; //Possibilities advert.possibility.advert_id = advert.id; advert.possibility.id = apos.id; advert.possibility.updated_date = DateTime.Now; dbContext.Entry(advert.possibility).State = System.Data.Entity.EntityState.Modified; //Properties advert.properties.advert_id = advert.id; advert.properties.id = ap.id; advert.properties.updated_date = DateTime.Now; dbContext.Entry(advert.properties).State = System.Data.Entity.EntityState.Modified; //Unavaiable Dates if (advert.unavaiable_date != null) { advert.unavaiable_date.ToList().ForEach(i => { i.advert_id = advert.id; dbContext.advert_unavaiable_dates.Add(i); }); } //Avaiable Dates if (advert.available_date != null) { advert.available_date.ToList().ForEach(ad => { for (DateTime date = ad.from_fulldate; date.Date <= ad.to_fulldate.Date; date = date.AddDays(1)) { AdvertAvailableDate avaiableDate = new AdvertAvailableDate() { day = date.Day, month = date.Month, year = date.Year, fulldate = date, uniq = String.Format("{0:MMddyyyy}", ad.from) + String.Format("{0:MMddyyyy}", ad.to), advert_id = advert.id }; dbContext.advert_avaiable_dates.Add(avaiableDate); } }); } dbContext.SaveChanges(); } return(Ok(advert)); }
public IHttpActionResult create([FromBody] _Message _message) { #region User Validation int user_id = Users.GetUserId(User); // get User Users user = db.users.Find(user_id); if (user == null) { return(NotFound()); } //Check user exist if (!db.users.Any(u => u.id == _message.user_id)) { return(NotFound()); } #endregion if (user_id == _message.user_id) { ExceptionThrow.Throw("Geçersiz mesaj istediği.", System.Net.HttpStatusCode.Forbidden); } List <_MessageDetail> msgList = new List <_MessageDetail>(); _MessageDetail msgDetail = new _MessageDetail() { date = DateTime.Now, fullname = user.name + " " + user.lastname, message = _message.message }; msgList.Add(msgDetail); //Create Message Messages message = new Messages() { last_message = new JavaScriptSerializer().Serialize(msgDetail), messages = new JavaScriptSerializer().Serialize(msgList), last_message_on = DateTime.Now }; db.messages.Add(message); db.SaveChanges(); //create User Messages UserMessages userMessage_Sender = new UserMessages() { is_owner = true, user_id = user_id, message_id = message.id, last_view = DateTime.Now }; UserMessages userMessage_Recipient = new UserMessages() { user_id = _message.user_id, message_id = message.id }; db.user_messages.Add(userMessage_Sender); db.user_messages.Add(userMessage_Recipient); db.SaveChanges(); Socket.Emit(_message.user_id, "message", new { id = message.id, message = msgDetail, last_view = DBNull.Value, user = new { fullname = user.name + " " + user.lastname, photo = user?.getPhotosUrl() } }); return(Ok(message)); }
public IHttpActionResult update([FromBody] Users user) { int user_id = Users.GetUserId(User); Users dbUser = db.users.Find(user_id); if (dbUser == null) { return(NotFound()); } if (dbUser.email != user.email && db.users.Any(u => u.email == user.email)) { ExceptionThrow.Throw("e-posta adresi kullanılmaktadır.", HttpStatusCode.BadRequest); } if (dbUser.gsm != user.gsm && db.users.Any(u => u.gsm == user.gsm)) { ExceptionThrow.Throw("gsm no kullanılmaktadır.", HttpStatusCode.BadRequest); } if (dbUser.gsm != user.gsm) { //generate activation code Random rnd = new Random(); string gsm_code = rnd.Next(9999, 999999).ToString(); dbUser.state = false; dbUser.gsm_state = false; dbUser.gsm_activation_code = gsm_code; //send gsm activation code NetGsm.Send(user.gsm, "menkule.com.tr uyeliginiz ile ilgili onay kodunuz: " + gsm_code); } dbUser.identity_no = user.identity_no; dbUser.gsm = user.gsm; dbUser.email = user.email; dbUser.name = user.name; dbUser.lastname = user.lastname; dbUser.updated_date = DateTime.Now; dbUser.identity_no = user.identity_no; db.SaveChanges(); try { } catch (Exception ex) { ExceptionThrow.Throw(ex); } return(Ok(new { name = user.name, lastname = user.lastname, email = user.email, gsm = user.gsm, gender = user.gender, photo = "", ownershiping = user.ownershiping, state = user.state, email_state = user.email_state, gsm_state = user.gsm_state, created_date = user.created_date })); }