コード例 #1
0
        /// <summary>
        ///     This controller handles enabling and disabling an advert
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="actionType"></param>
        /// <returns></returns>
        public ActionResult EnableOrDisableAdvert(string Id, string actionType)
        {
            var advertId      = Convert.ToInt64(new Md5Ecryption().DecryptPrimaryKey(Id, true));
            var advertisement = new AdvertsiementFactory().GetAdvertById((int)advertId);
            var loggedinuser  = Session["bhuinfologgedinuser"] as AppUser;

            if (loggedinuser != null)
            {
                if (advertisement != null)
                {
                    if (actionType == AdvertStatus.Enable.ToString())
                    {
                        advertisement.Status = AdvertStatus.Enable.ToString();
                    }
                    if (actionType == AdvertStatus.Disable.ToString())
                    {
                        advertisement.Status = AdvertStatus.Disable.ToString();
                    }
                    advertisement.DateLastModified = DateTime.Now;
                    _db.Entry(advertisement).State = EntityState.Modified;
                    _db.SaveChanges();
                    TempData["advert"] =
                        "This advert has been" + actionType + "successfully";
                    TempData["notificationtype"] = NotificationType.Success.ToString();
                    return(View("Index", _db.Advertisements.ToList()));
                }
            }
            else
            {
                TempData["advert"]           = "Your session has expired,Login Again!";
                TempData["notificationtype"] = NotificationType.Info.ToString();
                return(RedirectToAction("Index", "Advertisements"));
            }
            return(View("Index", _db.Advertisements.ToList()));
        }
コード例 #2
0
 public ActionResult VerifyAccessCode(FormCollection collectedValues)
 {
     if (ModelState.IsValid)
     {
         var accessCode  = collectedValues["AccessCode"];
         var advertExist = new AdvertsiementFactory().CheckIfAccessCodeExist(accessCode);
         if (advertExist != null)
         {
             return(View("CreateAdvert", advertExist));
         }
         TempData["advert"]           = "This access code is invalid!Check it and try again";
         TempData["notificationtype"] = NotificationType.Danger.ToString();
     }
     return(View());
 }
コード例 #3
0
        public ActionResult Edit(FormCollection collectedValues)
        {
            var loggedinuser = Session["bhuinfologgedinuser"] as AppUser;

            HttpPostedFileBase advertImage = null;

            if (Request.Files["Image"] != null)
            {
                advertImage = Request.Files["Image"];
            }
            var Id            = collectedValues["Id"];
            var advertId      = Convert.ToInt64(new Md5Ecryption().DecryptPrimaryKey(Id, true));
            var companyName   = collectedValues["AdvertCompanyName"];
            var advertisement = new AdvertsiementFactory().GetAdvertById((int)advertId);

            if (ModelState.IsValid)
            {
                if (loggedinuser != null)
                {
                    if (advertImage != null && advertImage.FileName != "")
                    {
                        advertisement.AdvertImage = new FileUploader().UploadFile(advertImage, UploadType.Advert);
                    }
                    advertisement.AdvertCompanyName = companyName;
                    advertisement.DateLastModified  = DateTime.Now;
                    advertisement.LastModifiedById  = loggedinuser.AppUserId;
                    advertisement.AdvertType        = collectedValues["AdvertType"];
                    _db.Entry(advertisement).State  = EntityState.Modified;
                    _db.SaveChanges();
                    TempData["advert"]           = "This advert has been modified successfully!";
                    TempData["notificationtype"] = NotificationType.Success.ToString();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["advert"]           = "Your session has expired,Login Again!";
                    TempData["notificationtype"] = NotificationType.Info.ToString();
                    return(RedirectToAction("Login", "Account"));
                }
            }
            return(View(advertisement));
        }
コード例 #4
0
        public ActionResult CreateAdvert(FormCollection collectedValues)
        {
            var advertImage   = Request.Files["Image"];
            var title         = collectedValues["Title"];
            var companyName   = collectedValues["AdvertCompanyName"];
            var advertId      = long.Parse(collectedValues["Id"]);
            var status        = collectedValues["Status"];
            var dateCreated   = collectedValues["Created"];
            var dateModified  = collectedValues["LastModified"];
            var createdBy     = long.Parse(collectedValues["CreatedBy"]);
            var modifiedBy    = long.Parse(collectedValues["ModifiedBy"]);
            var email         = collectedValues["Email"];
            var type          = collectedValues["Type"];
            var code          = collectedValues["AccessCode"];
            var content       = collectedValues["AdvertText"];
            var advertisement = new AdvertsiementFactory().GetAdvertById((int)advertId);

            if (ModelState.IsValid)
            {
                if (advertisement != null)
                {
                    advertisement.AccessCode        = code;
                    advertisement.AdvertType        = type;
                    advertisement.CreatedById       = createdBy;
                    advertisement.LastModifiedById  = modifiedBy;
                    advertisement.Email             = email;
                    advertisement.Status            = status;
                    advertisement.DateCreated       = Convert.ToDateTime(dateCreated);
                    advertisement.DateLastModified  = Convert.ToDateTime(dateModified);
                    advertisement.AdvertImage       = new FileUploader().UploadFile(advertImage, UploadType.Advert);
                    advertisement.Title             = title;
                    advertisement.AdvertCompanyName = companyName;
                    advertisement.AdvertText        = content;
                    _db.Entry(advertisement).State  = EntityState.Modified;
                    _db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(advertisement));
        }