Exemplo n.º 1
0
        public ActionResult Delete(int id, int page = 0)
        {
            var user = _db.UserLogins.Find(id);

            if (user != null)
            {
                var itsthmb = _db.ProductThumbs.Where(x => x.UserId == user.UserId);
                foreach (var productThumb in itsthmb)
                {
                    _db.ProductThumbs.Remove(productThumb);
                }

                var itscmt = _db.UserComments.Where(x => x.UserId == user.UserId);
                foreach (var userComment in itscmt)
                {
                    _db.UserComments.Remove(userComment);
                }

                var itsnotif = _db.Notifications.Where(x => x.UserId == user.UserId || x.OriginatorId == user.UserId);
                foreach (var notification in itsnotif)
                {
                    _db.Notifications.Remove(notification);
                }

                var itsjob = _db.JobPostings.Where(x => x.UserId == user.UserId);
                foreach (var item in itsjob)
                {
                    _db.JobPostings.Remove(item);
                }

                _db.UserLogins.Remove(user);
                _db.SaveChanges();
            }
            return(RedirectToAction("Index", "Admin", new { page = page }));
        }
Exemplo n.º 2
0
        public ActionResult Register(RegisterModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    using (var db = new OnlineShoppingEntity())
                    {
                        if (db.UserLogins.FirstOrDefault(x => x.UserName == model.UserName) !=
                            null)
                        {
                            ModelState.AddModelError(model.UserName, "User name is already taken.");
                            return(View(model));
                        }
                        if (db.UserLogins.FirstOrDefault(x => x.Email == model.Email) !=
                            null)
                        {
                            ModelState.AddModelError(model.UserName, "Email address is already registered.");
                            return(View(model));
                        }

                        var saltKey      = Helper.CreateSaltKey(5);
                        var passwordHash = Helper.CreatePasswordHash(model.Password, saltKey);

                        db.UserLogins.Add(new UserLogin()
                        {
                            UserName      = model.UserName,
                            Password      = passwordHash,
                            Address       = model.Address,
                            ContactNumber = model.ContactNumber,
                            Email         = model.Email,
                            FullName      = model.FullName,
                            JoinedDate    = DateTime.UtcNow,
                            PasswordSalt  = saltKey
                        });
                        db.SaveChanges();
                        this.Login(new LoginModel {
                            UserName = model.UserName, Password = model.Password, RememberMe = false
                        });

                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return(this.Redirect(returnUrl));
                        }
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Edit(JobEditModel request)
        {
            var uId = Convert.ToInt32(Session["UserId"]);

            if (ModelState.IsValid && uId > 0)
            {
                var job = _db.JobPostings.Find(request.JobId);
                if (job == null)
                {
                    return(HttpNotFound());
                }
                if (job.UserId != uId)
                {
                    ModelState.AddModelError(string.Empty, "The job is not posted by this user.");
                    return(View(request));
                }
                if (request.LastDate < DateTime.Today)
                {
                    ModelState.AddModelError(string.Empty, "The end date should be a future date.");
                    return(View(request));
                }
                job.CompanyName    = request.CompanyName;
                job.Title          = request.Title;
                job.Salary         = request.Salary;
                job.Experience     = request.Experience;
                job.Openings       = request.Openings;
                job.Education      = request.Education;
                job.City           = request.City;
                job.Contact        = request.Contact;
                job.Email          = request.Email;
                job.URL            = request.Url;
                job.EndDate        = request.LastDate;
                job.Requirements   = request.Requirements;
                job.Specifications = request.Specifications;
                _db.SaveChanges();

                return(RedirectToAction("Detail", new { id = job.JobId }));
            }
            return(View(request));
        }
        public ActionResult NotifList(int page = 0)
        {
            var uId = 0;

            int.TryParse(Convert.ToString(Session["UserId"]), out uId);
            if (uId > 0)
            {
                var result =
                    _db.Notifications
                    .Where(x => x.UserId == uId)
                    .OrderByDescending(x => x.SentDate)
                    .Select(
                        x =>
                        new NotificationModel
                {
                    NotificationId     = x.NotificationId,
                    UserId             = x.OriginatorId,
                    FullName           = x.UserLogin1.FullName,
                    NotificationTypeId = x.NotificationTypeId,
                    ProductId          = x.ProductId,
                    ProductName        = x.Product.Name,
                    SentDate           = x.SentDate,
                    IsNew = x.ReadDate == null
                });

                var presult = new PaginatedList <NotificationModel>(result, page, 10, 5);
                foreach (var notificationModel in presult)
                {
                    _db.Notifications.Find(notificationModel.NotificationId).ReadDate = DateTime.Now;
                }
                _db.SaveChanges();

                return(View(presult));
            }
            return(RedirectToAction("Login", "Account"));
        }
        public ActionResult Edit(UserEditModel userInfo)
        {
            var uId = Convert.ToInt32(Session["UserId"]);

            if (ModelState.IsValid && uId > 0)
            {
                var userlogin = db.UserLogins.Find(uId);
                if (userlogin == null)
                {
                    return(HttpNotFound());
                }
                userlogin.Address       = userInfo.Address;
                userlogin.ContactNumber = userInfo.ContactNumber;
                userlogin.FullName      = userInfo.FullName;
                db.SaveChanges();

                return(RedirectToAction("Index", new { id = uId }));
            }
            return(View(userInfo));
        }
Exemplo n.º 6
0
        public ActionResult Create(ProductModel model)
        {
            if (ModelState.IsValid)
            {
                var fileName = string.Empty;
                if (model.Image != null &&
                    model.Image.ContentType.StartsWith("Image", StringComparison.OrdinalIgnoreCase))
                {
                    fileName  = Guid.NewGuid().ToString();
                    fileName += model.Image.FileName.Substring(model.Image.FileName.LastIndexOf("."));
                    var fullName = System.IO.Path.Combine(Server.MapPath("~/Images"), "Products", fileName);
                    model.Image.SaveAs(fullName);
                }

                _db.Products.Add(new Product()
                {
                    Added             = DateTime.UtcNow,
                    Description       = model.Description,
                    Image             = fileName,
                    Name              = model.ProductName,
                    ProductCategoryId = model.SubCategoryId,
                    UserId            = Convert.ToInt32(Session["UserId"]),
                    ExpiryDate        = model.ExpiryDate,
                    Price             = model.Price,
                    IsUsed            = model.IsUsed
                });
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            model.Categories    = GetCategories();
            model.SubCategories = new List <SelectListItem>(
                _db.ProductCategories.ToList()
                .Where(x => x.MainCategoryId == Convert.ToInt32(model.Categories.FirstOrDefault().Value))
                .Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.ProductCategoryId.ToString()
            }));
            return(View(model));
        }