Exemple #1
0
        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));
        }