Exemplo n.º 1
0
        public ActionResult DangTin(Models.PostBDS model, FormCollection frm, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var post = new Post();
                    post.Title   = model.Title;
                    post.Content = model.Content;
                    post.Hot     = false;
                    post.Created = DateTime.Now;
                    if (CurrentUser != null)
                    {
                        post.Status = (int)PostStatus.Enabled;
                    }
                    else
                    {
                        post.Status = (int)PostStatus.Init;
                    }
                    post.ContactName  = model.ContactName;
                    post.ContactPhone = model.ContactPhone;
                    post.ContactEmail = model.ContactEmail;
                    if (model.Money != null)
                    {
                        post.Money = (decimal)model.Money;
                    }
                    post.Province  = model.Province;
                    post.District  = model.District;
                    post.Ward      = model.Ward;
                    post.LoaiBDSID = model.LoaiBDSID;
                    post.HinhThuc  = model.HinhThuc;

                    var db = DB.Entities;
                    db.Post.AddObject(post);
                    db.SaveChanges();
                    #region Uploads
                    int autoIncrement = 1;
                    foreach (var item in files)
                    {
                        if (item != null)
                        {
                            string filename = post.ID + "_" + autoIncrement + ".jpg";
                            item.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename));
                            var img = new ImagePost();
                            img.PostID = post.ID;
                            img.Url    = "/Uploads/" + filename;
                            img.Title  = frm["imgtitle" + autoIncrement];
                            db.ImagePost.AddObject(img);
                            autoIncrement++;
                        }
                    }
                    db.SaveChanges();
                    #endregion
                    return(RedirectToAction("Thanks", new { @hidefilter = 1 }));
                }
                catch { return(View(model)); }
            }
            return(View(model));
        }
Exemplo n.º 2
0
 public ActionResult DangTin()
 {
     Models.PostBDS model = new Models.PostBDS()
     {
         Province = 1
     };
     if (CurrentUser != null)
     {
         model.ContactName  = CurrentUser.Name;
         model.ContactPhone = CurrentUser.PhoneNumber;
         model.ContactEmail = CurrentUser.Email;
     }
     return(View(model));
 }