public ActionResult CreateClassified(ClassifiedModel model) { if (ModelState.IsValid) { var validate = new IValidate(); var user = _readOnlyRepository.FirstOrDefault <AccountLogin>(x => x.Email == HttpContext.User.Identity.Name); var classifiedsList = user.AccountClassifieds.ToList(); classifiedsList.Add(new Classifieds(model.Category, model.Article, model.ArticleModel, model.Location, model.Price, model.Description, user.Email, model.UrlImage, model.UrlImage1, model.UrlImage2, model.UrlImage3, model.UrlImage4, validate.Embed(model.UrlVideo))); user.AccountClassifieds = classifiedsList; _writeOnlyRepository.Update(user); var notifyList = _readOnlyRepository.GetAll <Subscriptions>().Where(x => x.Following == user.Id && !x.Archived); if (!notifyList.Any()) { foreach (var x in notifyList) { var userToBeNotify = _readOnlyRepository.FirstOrDefault <AccountLogin>(z => z.Id == x.Follower); var list = userToBeNotify.Notifications.ToList(); list.Add(new Notifications(user.Email, model.Article, "Classi")); userToBeNotify.Notifications = list; _writeOnlyRepository.Update(userToBeNotify); } } //check MessageBox.Show("Classified added successfully"); } return(View("CreateClassified", model)); }
public ActionResult NewClassified(ClassifiedModel clasificado) { if (ModelState.IsValid) { switch (ValidateImagesVideo(clasificado)) { case true: break; case false: return(View(clasificado)); } var user = (string)Session["User"]; var usuario = _readOnlyRepository.FirstOrDefault <User>(x => x.Nombre == user); clasificado.IdUsuario = usuario.Id; var classified = new Classified { FechaCreacion = DateTime.Now.ToString("d"), Titulo = clasificado.Titulo, Categoria = clasificado.Categoria, IdUsuario = clasificado.IdUsuario, Negocio = clasificado.Negocio, Descripcion = clasificado.Descripcion, Precio = clasificado.Precio, UrlVideo = clasificado.UrlVideo, UrlImg0 = clasificado.UrlImg0, UrlImg1 = clasificado.UrlImg1, UrlImg2 = clasificado.UrlImg2, UrlImg3 = clasificado.UrlImg3, UrlImg4 = clasificado.UrlImg4, UrlImg5 = clasificado.UrlImg5, Recomendado = 1 }; _writeOnlyRepository.Create(classified); usuario.TotalClasificados += 1; _writeOnlyRepository.Update(usuario); var subscriptions = _readOnlyRepository.GetAll <Suscribtions>().ToList(); foreach (var sus in subscriptions) { var subs = _readOnlyRepository.GetById <User>(sus.IdUsuarioSuscrito); TwilioService.SendSmsToSubscribers(subs.Nombre, classified.Titulo, usuario.Nombre); } this.AddNotification("Clasificado registrado.", NotificationType.Success); return(RedirectToAction("Index", "Home")); } this.AddNotification("No se pudo crear clasificado.", NotificationType.Error); return(View(clasificado)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_classifieds_details); _activity = this; int classifiedId = Intent.GetIntExtra("ClassifiedId", 0); int organizationId = Intent.GetIntExtra("OrganizationId", 0); int classifiedDetailsId = Intent.GetIntExtra("ClassifiedDetailsId", 0); _classified = Repository.Classifieds.Where(c => c.Id == classifiedId).FirstOrDefault(); _organization = Repository.Organizations.Where(c => c.Id == organizationId).FirstOrDefault(); _classifiedDetails = Repository.ClassifiedDetails.Where(c => c.Id == classifiedDetailsId).FirstOrDefault(); var titleTextView = FindViewById <TextView>(Resource.Id.classified_details_title); var subtitleTextView = FindViewById <TextView>(Resource.Id.classified_details_subtitle); var addressTextView = FindViewById <TextView>(Resource.Id.classified_details_address); var phoneTextView = FindViewById <TextView>(Resource.Id.classified_details_phone); var dateTextView = FindViewById <TextView>(Resource.Id.classified_details_date); var descriptionTextView = FindViewById <TextView>(Resource.Id.classified_details_description); _btn = FindViewById <Button>(Resource.Id.classified_details_btn); titleTextView.Text = _organization.Name; subtitleTextView.Text = _classified.Subtitle; addressTextView.Text = _organization.Address; phoneTextView.Text = _organization.Phone; dateTextView.Text = $"{_classified.StartDate} - {_classified.EndDate}"; descriptionTextView.Text = _classifiedDetails.Description; _btn.Text = "Wezmę udział"; _btn.SetOnClickListener(new BtnObClickListener()); _accepted = Repository.AcceptedClassified.Where(a => a.UserId == CurrentSession.UserId && a.ClassifiedId == _classified.Id).FirstOrDefault(); if (_accepted != null) { _btn.Text = "Rezygnuję"; _btn.SetBackgroundResource(Resource.Drawable.round_red_background); _btn.SetTextColor(Android.Graphics.Color.ParseColor("#b71c1c")); } }
private bool ValidateImagesVideo(ClassifiedModel clasificado) { if (clasificado.UrlVideo != null) { switch (RemoteFileExists(clasificado.UrlVideo)) { case true: break; case false: this.AddNotification("Url de Video no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg0)) { switch (RemoteFileExists(clasificado.UrlImg0)) { case true: break; case false: this.AddNotification("Url de imagen 0 no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg1)) { switch (RemoteFileExists(clasificado.UrlImg1)) { case true: break; case false: this.AddNotification("Url de imagen 1 no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg2)) { switch (RemoteFileExists(clasificado.UrlImg2)) { case true: break; case false: this.AddNotification("Url de imagen 2 no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg3)) { switch (RemoteFileExists(clasificado.UrlImg3)) { case true: break; case false: this.AddNotification("Url de imagen 4 no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg4)) { switch (RemoteFileExists(clasificado.UrlImg4)) { case true: break; case false: this.AddNotification("Url de imagen 4 no existe o no es valido!", NotificationType.Error); return(false); } } if (!String.IsNullOrEmpty(clasificado.UrlImg5)) { switch (RemoteFileExists(clasificado.UrlImg5)) { case true: break; case false: this.AddNotification("Url de imagen 5 no existe o no es valido!", NotificationType.Error); return(false); } } return(true); }
public ActionResult AddThreadPost(AddThreadViewModel addThreadViewModel) { bool isLoggedIn = false; var httpCookie = Request.Cookies["LogOnCookie"]; if (httpCookie != null) { isLoggedIn = true; } ViewBag.Username = addThreadViewModel.Username; ViewBag.Email = addThreadViewModel.Email; if (addThreadViewModel.ThreadRadio == "announcement") { if (String.IsNullOrEmpty(addThreadViewModel.Announcement) || String.IsNullOrEmpty(addThreadViewModel.TagsAnnouncement)) { return(View("AddThread")); } ViewBag.Announcement = addThreadViewModel.Announcement; ViewBag.TagsA = addThreadViewModel.TagsAnnouncement; } if (addThreadViewModel.ThreadRadio == "generalThread") { if (String.IsNullOrEmpty(addThreadViewModel.Title) || String.IsNullOrEmpty(addThreadViewModel.Content) || String.IsNullOrEmpty(addThreadViewModel.TagsGeneral)) { return(View("AddThread")); } ViewBag.Title = addThreadViewModel.Title; ViewBag.Content = addThreadViewModel.Content; ViewBag.TagsG = addThreadViewModel.TagsGeneral; } if (!isLoggedIn) { if (_unitOfWork.DoesUserNameOrEmailExist(addThreadViewModel.Username) == 1) { ViewBag.Error = "Username already exists!"; return(View("AddThread")); } if (_unitOfWork.DoesUserNameOrEmailExist(addThreadViewModel.Email) == 2) { ViewBag.Error = "Email already exists!"; return(View("AddThread")); } } var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted } ); try { using (scope){ if (!isLoggedIn) { var pass = System.Web.Security.Membership.GeneratePassword(10, 2); var passencrypted = Encryption.Encrypt(pass); var userModel = new UserModel { Username = ViewBag.Username, Email = ViewBag.Email, Password = passencrypted, ConfirmPassword = pass, IpAddress = GetIp(), Browser = Request.Browser.Browser, CreatedOn = DateTime.Now, LastSuccessfulLogin = DateTime.Now }; _unitOfWork.UserRepository.Insert(userModel); _unitOfWork.Save(); _unitOfWork.SendEmail(ViewBag.Email, "Your password for " + Constants.Domain, "Dear " + ViewBag.Username + ",<br />" + "You just posted a thread and thank you for your contribution. <br />Please find the auto generated temporary password." + "<br />Temporary Password:"******"<br />You may want to login with this and change it once you login.<br /><br /> Thanking you <br />" + Constants.Domain + "<br/>" + Constants.Slogan); } if (addThreadViewModel.ThreadRadio == null && addThreadViewModel.TagsAnnouncement == null && addThreadViewModel.TagsGeneral == null) { var cm = new ClassifiedModel(); var objClassifiedModel = PopulateClassifiedModel(cm, addThreadViewModel); _unitOfWork.ClassifiedRepository.Insert(objClassifiedModel); _unitOfWork.Save(); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.Classifieds); } else { var threadModel = new ThreadModel { Username = ViewBag.Username, Email = ViewBag.Email, ThreadRadio = addThreadViewModel.ThreadRadio, Announcement = addThreadViewModel.Announcement, TagsAnnouncement = addThreadViewModel.TagsAnnouncement, Title = addThreadViewModel.Title, Content = addThreadViewModel.Content, TagsGeneral = addThreadViewModel.TagsGeneral, IpAddress = GetIp(), Browser = Request.Browser.Browser, SubmittedOn = DateTime.Now, LastUpdated = DateTime.Now, Likes = 0, Views = 0, Responses = 0 }; _unitOfWork.ThreadRepository.Insert(threadModel); _unitOfWork.Save(); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.RecentThreads); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.TrendingTagsAnnouncement); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.TrendingTagsGeneral); } scope.Complete(); } ViewBag.Username = null; ViewBag.Email = null; ViewBag.Announcement = null; ViewBag.TagsA = null; ViewBag.Title = null; ViewBag.Content = null; ViewBag.TagsG = null; } catch (Exception ex) { scope.Dispose(); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } var cookieLogOn = new HttpCookie("LogOnCookie"); cookieLogOn.Values["username"] = addThreadViewModel.Username; cookieLogOn.Values["email"] = addThreadViewModel.Email; cookieLogOn.Expires = DateTime.Now.AddDays(2); Response.Cookies.Add(cookieLogOn); return(RedirectToAction("Index", "Home")); }