public void Edit(int id)
        {
            advertisement advertisement = ActiveRecordBase <advertisement> .Find(id);

            PropertyBag["advertisementimages"] = advertisement.Images;
            PropertyBag["tags"] = ActiveRecordBase <tags> .FindAll();

            PropertyBag["advertisement"] = ActiveRecordBase <advertisement> .Find(id);

            media_types imgtype = ActiveRecordBase <media_types> .Find(2);

            PropertyBag["images"] = imgtype.media_typed;
            //PropertyBag["images"] = ActiveRecordBase<media_repo>.FindAll();
            PropertyBag["authors"] = ActiveRecordBase <users> .FindAll();

            //PropertyBag["classifiedtype"] = ActiveRecordBase<ClassifiedType>.FindAll();
            //PropertyBag["location"] = ActiveRecordBase<LocationType>.FindAll();
            List <tags> tags = new List <tags>();

            tags.AddRange(ActiveRecordBase <advertisement> .Find(id).Tags);
            int tagscounts = 0;

            if (ActiveRecordBase <advertisement> .Find(id).Tags != null)
            {
                tagscounts = ActiveRecordBase <advertisement> .Find(id).Tags.Count;
            }

            for (int i = tagscounts; i < 2; i++)
            {
                tags.Add(new tags());
            }
            PropertyBag["advertisementtags"] = tags;
            RenderView("new");
        }
        public ActionResult DeleteConfirmed(int id)
        {
            advertisement advertisement = db.Advertisements.Find(id);

            db.Advertisements.Remove(advertisement);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void DeleteTag(int id, int advertisementId)
        {
            tags tag = ActiveRecordBase <tags> .Find(id);

            advertisement advertisement = ActiveRecordBase <advertisement> .Find(advertisementId);

            advertisement.Tags.Remove(tag);
            ActiveRecordMediator <advertisement> .Save(advertisement);
        }
        public void delete(int id)
        {
            advertisement advertisement = ActiveRecordBase <advertisement> .Find(id);

            ActiveRecordMediator <advertisement> .Delete(advertisement);

            RedirectToReferrer();
            CancelLayout();
            RedirectToAction("list");
        }
 public ActionResult Edit([Bind(Include = "advertisementId,information,validity")] advertisement advertisement)
 {
     if (ModelState.IsValid)
     {
         db.Entry(advertisement).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(advertisement));
 }
        public void DeleteImage(int id, int imageid)
        {
            media_repo image = ActiveRecordBase <media_repo> .Find(imageid);

            advertisement advertisement = ActiveRecordBase <advertisement> .Find(id);

            advertisement.Images.Remove(image);
            ActiveRecordMediator <advertisement> .Save(advertisement);

            CancelLayout();
            RenderText("true");
        }
        // GET: advertisements/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            advertisement advertisement = db.Advertisements.Find(id);

            if (advertisement == null)
            {
                return(HttpNotFound());
            }
            return(View(advertisement));
        }
示例#8
0
 //common lib
 public bool Insert(advertisement entity)
 {
     try
     {
         entity.created_at  = DateTime.Now;
         entity.modified_at = DateTime.Now;
         entity.click_count = 0;
         db.advertisements.Add(entity);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public ActionResult Create(advertisement advertisement, HttpPostedFileBase file1)
        {
            if (ModelState.IsValid)
            {
                advertisement.pageId = User.Identity.GetUserId();
                if (file1 != null)
                {
                    advertisement.pics = new byte[file1.ContentLength];
                    file1.InputStream.Read(advertisement.pics, 0, file1.ContentLength);
                    db.Advertisements.Add(advertisement);
                    db.SaveChanges();
                }
                return(RedirectToAction("advertisementView"));
            }

            return(View("advertisementView"));
        }
        public bool Update(advertisement entity)
        {
            try
            {
                var ads = db.advertisements.Find(entity.ID);

                ads.Content = entity.Content;
                ads.Link    = entity.Link;
                ads.Image   = entity.Image;
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                //có thể làm ghi log
                return(false);
            }
        }
示例#11
0
        public ActionResult EditAd(advertisement ads)
        {
            if (ModelState.IsValid)
            {
                var dao = new advertisementDAO();

                bool update = dao.Update(ads);
                if (update)
                {
                    setAlert("Sửa nội dung quảng cáo thành công", "success");
                    return(RedirectToAction("ListAd", "Advertisement"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật thông tin thất bại");
                }
            }
            return(View("ListAd"));
        }
示例#12
0
 public bool Update(advertisement entity)
 {
     try
     {
         var info = db.advertisements.Find(entity.id);
         info.url_image                 = entity.url_image;
         info.url_source                = entity.url_source;
         info.description_ad            = entity.description_ad;
         info.display_order             = entity.display_order;
         info.advertisement_position_id = entity.advertisement_position_id;
         info.modified_by               = entity.modified_by;
         info.modified_at               = DateTime.Now;
         info.is_active                 = entity.is_active;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public ActionResult Edit(advertisement ad)
        {
            if (ModelState.IsValid)
            {
                var dao     = new ads_dao();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                ad.modified_by = session.username;

                var result = dao.Update(ad);
                if (result)
                {
                    SetAlert(StaticResources.Resources.Pub_UpdateSucess, "success");
                    return(RedirectToAction("Index", "Advertisement"));
                }
                else
                {
                    ModelState.AddModelError("", StaticResources.Resources.UpdateAdsPostitionFailed);
                }
            }
            SetListPosition(ad.advertisement_position_id);
            return(View());
        }
        public ActionResult Create(advertisement ad)
        {
            if (ModelState.IsValid)
            {
                var dao     = new ads_dao();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                ad.created_by = session.username;

                bool result = dao.Insert(ad);
                if (result)
                {
                    SetAlert(StaticResources.Resources.Pub_InsertSuccess, "success");
                    return(RedirectToAction("Index", "Advertisement"));
                }
                else
                {
                    ModelState.AddModelError("", StaticResources.Resources.InsertAdvertisementFailed);
                }
            }
            SetListPosition();
            return(View());
        }
 public ActionResult Create(advertisement adver)
 {
     if (ModelState.IsValid)
     {
         var merchant   = (Account)Session[Common.CommonConstants.USER_INFO_SESSION];
         var daoAd      = new advertisementDAO();
         var daoOrderAd = new OrderAdvertisementDAO();
         adver.Merchant = merchant.ID;
         adver.CTR      = 0;
         adver.Status   = false;
         var  price = new LocationAdDAO().GetDetail(adver.Location).Price;
         long id    = daoAd.Insert(adver);
         if (id > 0)
         {
             var orderAd = new OrderAdvertisement();
             orderAd.IDAd       = id;
             orderAd.IDmerchant = adver.Merchant;
             orderAd.StartDate  = adver.ActiveDate;
             orderAd.EndDate    = adver.EndDate;
             TimeSpan Days = (TimeSpan)(orderAd.EndDate - orderAd.StartDate);
             orderAd.Price      = Days.Days * price;
             orderAd.Status     = 0;
             orderAd.CreateDate = DateTime.Now;
             long idorder = daoOrderAd.Insert(orderAd);
             if (idorder > 0)
             {
                 return(RedirectToAction("Index", "Advertisment"));
             }
         }
         else
         {
             ModelState.AddModelError("", "Thêm sản phẩm thất bại");
         }
     }
     return(View("Index"));
 }
        public void Update([ARDataBind("advertisement", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] advertisement advertisement,
                           [ARDataBind("tags", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] tags[] tags, String[] newtag,
                           [ARDataBind("images", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] media_repo[] images)
        {
            if (advertisement.HtmlText == null && (advertisement.Url == null && images.Length == 0))
            {
                Flash["error"] = "You may not set a empty advertisment";
                RedirectToReferrer();
                return;
            }
            //string output = JsonConvert.SerializeObject(advertisement.limitAds);

            advertisement.Tags.Clear();
            advertisement.Images.Clear();
            try
            {
                if (newtag != null)
                {
                    foreach (String oneTag in newtag)
                    {
                        if (oneTag != "")
                        {
                            tags t = new tags();
                            t.name = oneTag;
                            tags[] temp = ActiveRecordBase <tags> .FindAllByProperty("Name", oneTag);

                            if (temp.Length == 0)
                            {
                                ActiveRecordMediator <tags> .Save(t);

                                advertisement.Tags.Add(t);
                            }
                        }
                    }
                }



                foreach (tags tag in tags)
                {
                    if (tag.id > 0)
                    {
                        advertisement.Tags.Add(tag);
                    }
                }

                foreach (media_repo image in images)
                {
                    if (image.id > 0)
                    {
                        advertisement.Images.Add(image);
                    }
                }

                /*if (advertisement.Location.id == 0)
                 * {
                 *  advertisement.Location.id = 2;
                 * }*/

                ActiveRecordMediator <advertisement> .Save(advertisement);
            }


            catch (Exception ex)
            {
                Flash["error"]         = ex.Message;
                Flash["advertisement"] = advertisement;
            }
            RedirectToAction("list");
        }
 public long Insert(advertisement entity)
 {
     db.advertisements.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }