Example #1
0
        /// <summary>
        ///  Insert pending picture in database
        /// </summary>
        /// <param name="netname"></param>
        /// <param name="picture"></param>
        public void AddPendingPicture(string netname, byte[] picture)
        {
            var student = _database.STUDENTS
                          .Where(s => s.NETNAME == netname)
                          .FirstOrDefault();

            student.UPDATEPICTURE = false; // so he can't send multiple update
            student.PENDING       = true;


            PICTURE pendingPicture = new PICTURE
            {
                PICTURE_DATA    = picture,
                STATUS          = Status.Pending.ToString(),
                CREATED         = DateTime.UtcNow,
                STUDENT_NETNAME = netname
            };

            _database.PICTUREs.Add(pendingPicture);
            _database.SaveChanges();
        }
        public ActionResult PostProject(HttpPostedFileBase Avatar, PROPERTY property, List <HttpPostedFileBase> Images, PostModel model, List <string> feature)
        {
            if (ModelState.IsValid)
            {
                string avatar = "";
                if (Avatar.ContentLength > 0)
                {
                    var filename = Path.GetFileName(Avatar.FileName);
                    var path     = Path.Combine(Server.MapPath("~/img"), filename);
                    Avatar.SaveAs(path);
                    avatar = filename;
                }
                //add picture
                foreach (HttpPostedFileBase img in Images)
                {
                    if (img != null)
                    {
                        if (img.ContentLength > 0)
                        {
                            var filename = Path.GetFileName(img.FileName);
                            var path     = Path.Combine(Server.MapPath("~/img/"), filename);
                            img.SaveAs(path);
                            PICTURE pic = new PICTURE();
                            pic.Name_Image  = filename;
                            pic.Property_id = property.ID;
                            db.PICTUREs.Add(pic);
                        }
                    }
                    else
                    {
                        break;
                    }
                }



                //string image = "";
                //if (Image.ContentLength > 0)
                //{
                //    var filename = Path.GetFileName(Image.FileName);
                //    var path = Path.Combine(Server.MapPath("~/img"), filename);
                //    Image.SaveAs(path);
                //    image = filename;
                //}
                var pro = new PROPERTY();
                pro.PropertyName    = model.PropertyName;
                pro.PropertyType_ID = model.PropertyType_ID;
                pro.Avatar          = avatar;
                //pro.Images = image;
                //pro.DISTRICT = model.DISTRICT;
                pro.District_ID = model.District_ID;
                pro.Street_ID   = model.Street_ID;
                pro.Ward_ID     = model.Ward_ID;
                //pro.STREET = model.STREET;
                pro.Price        = model.Price;
                pro.Area         = model.Area;
                pro.BathRoom     = model.BathRoom;
                pro.BedRoom      = model.BedRoom;
                pro.PackingPlace = model.PackingPlace;
                pro.Content      = model.Content;
                pro.UnitPrice    = model.UnitPrice;

                //add feature

                var fetur = new PROPERTY_FEATURE();
                if (feature != null)
                {
                    foreach (string fetus in feature)
                    {
                        //PROPERTY_FEATURE profeature = new PROPERTY_FEATURE();
                        // fetur.Property_ID = qqq.ID;
                        fetur.Feature_ID  = db.FEATUREs.SingleOrDefault(x => x.FeatureName == fetus).ID;
                        fetur.Property_ID = property.ID;
                        //fetur.Feature_ID = 1;
                        db.PROPERTY_FEATURE.Add(fetur);
                    }
                }

                pro.Status_ID  = model.Status_ID;
                pro.Updated_at = DateTime.Now;
                pro.Created_at = DateTime.Now;
                pro.UserID     = (int)Session["UserID"];
                db.PROPERTies.Add(pro);
                db.SaveChanges();
                //ViewBag.Success = "Đăng ký thành công";
                model = new PostModel();
                return(RedirectToAction("List", "Project"));
            }
            else
            {
                ModelState.AddModelError("", "Đăng bài không thành công, vui lòng kiểm tra lại các trường thông tin của bạn");
            }
            return(View(model));
        }
Example #3
0
 partial void DeletePICTURE(PICTURE instance);
Example #4
0
 partial void UpdatePICTURE(PICTURE instance);
Example #5
0
 partial void InsertPICTURE(PICTURE instance);
Example #6
0
	private void detach_PICTUREs(PICTURE entity)
	{
		this.SendPropertyChanging();
		entity.UNIT = null;
	}
Example #7
0
	private void attach_PICTUREs(PICTURE entity)
	{
		this.SendPropertyChanging();
		entity.UNIT = this;
	}
        public ActionResult Edit(int id, PROPERTY p, List <string> feature, List <HttpPostedFileBase> Images)
        {
            PROPERTY proper   = model.PROPERTies.Find(p.ID);
            var      property = model.PROPERTies.FirstOrDefault(x => x.ID == id);
            var      feat     = model.PROPERTY_FEATURE.Where(x => x.Property_ID == p.ID).ToList();
            var      image    = model.PICTUREs.Where(x => x.Property_id == p.ID);

            model.PICTUREs.RemoveRange(image);
            model.PROPERTY_FEATURE.RemoveRange(feat);

            property.PropertyName = p.PropertyName;
            property.UnitPrice    = p.UnitPrice;
            property.Price        = p.Price;
            property.BathRoom     = p.BathRoom;
            property.BedRoom      = p.BedRoom;
            property.Content      = p.Content;
            property.Create_post  = p.Create_post;
            property.Created_at   = p.Created_at;
            property.DISTRICT     = p.DISTRICT;
            property.STREET       = p.STREET;
            property.WARD         = p.WARD;
            property.Area         = p.Area;
            property.Status_ID    = p.Status_ID;
            foreach (HttpPostedFileBase img in Images)
            {
                if (img != null)
                {
                    if (img.ContentLength > 0)
                    {
                        var filename = Path.GetFileName(img.FileName);
                        var path     = Path.Combine(Server.MapPath("~/img/"), filename);
                        img.SaveAs(path);
                        PICTURE pic = new PICTURE();
                        pic.Name_Image  = filename;
                        pic.Property_id = property.ID;
                        model.PICTUREs.Add(pic);
                    }
                    else
                    {
                        model.SaveChanges();
                    }
                }
                else
                {
                    model.SaveChanges();
                }
            }
            //add feature

            //    foreach (var featu in feature)
            //    {
            //        PROPERTY_FEATURE proferty_fea = new PROPERTY_FEATURE();

            //        proferty_fea.Feature_ID = model.FEATUREs.SingleOrDefault(x => x.FeatureName == featu).ID;
            //        proferty_fea.Property_ID = p.ID;
            //        model.PROPERTY_FEATURE.Add(proferty_fea);
            //    }

            model.SaveChanges();
            return(RedirectToAction("Index"));
        }