Example #1
0
        public ActionResult Delete(int id)
        {
            var de = db.PROPERTies.First(p => p.ID == id);

            db.PROPERTies.Remove(de);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
        public void CleanDatabase()
        {
            using (var db = new K21T1_Team4Entities1())
            {
                db.PROPERTY_IMAGE.RemoveRange(db.PROPERTY_IMAGE);
                db.PROPERTY_FEATURE.RemoveRange(db.PROPERTY_FEATURE);
                db.PROPERTies.RemoveRange(db.PROPERTies);

                db.SaveChanges();
            }
        }
        public void Property(Table project)
        {
            PROPERTY p = new PROPERTY();

            p.PropertyName = project.Rows[0]["PropertyName"];
            p.Content      = project.Rows[0]["Content"];
            p.Price        = int.Parse(project.Rows[0]["Price"]);
            p.Area         = project.Rows[0]["Area"];
            p.BedRoom      = int.Parse(project.Rows[0]["BedRoom"]);
            p.PackingPlace = int.Parse(project.Rows[0]["PackingPlace"]);
            p.Status_ID    = db.PROJECT_STATUS.ToList().FirstOrDefault(s => s.Status_Name == project.Rows[0]["Status_Name"]).ID;
            db.PROPERTies.Add(p);
            db.SaveChanges();
            var propertyID = db.PROPERTies.ToList().FirstOrDefault(u => u.PropertyName == project.Rows[0]["PropertyName"]).ID;
        }
Example #4
0
        public void InsertProjectToDB(Table projects)
        {
            using (var db = new K21T1_Team4Entities1())
            {
                var oStreets = db.STREETs.ToList();

                foreach (var item in projects.Rows)
                {
                    var tPropertyType = item["PropertyType"].ToString();
                    var tStreet_ID    = item["Street"].ToString();
                    var tDistrict_ID  = item["District"].ToString();
                    var tWard_ID      = item["Ward"].ToString();
                    var tPropertyName = item["PropertyName"].ToString();
                    var tUnitPrice    = item["UnitPrice"].ToString();
                    var tContent      = item["Content"].ToString();

                    var a  = db.PROPERTY_TYPE.FirstOrDefault(d1 => d1.CodeType == tPropertyType);
                    var b  = db.STREETs.FirstOrDefault(s => s.StreetName == tStreet_ID);
                    var c  = db.DISTRICTs.FirstOrDefault(d2 => d2.DistrictName == tDistrict_ID);
                    var d3 = db.WARDs.FirstOrDefault(d2 => d2.WardName == tWard_ID);


                    PROPERTY project = new PROPERTY()
                    {
                        PropertyName    = item["PropertyName"].ToString(),
                        PropertyType_ID = a.ID,
                        Street_ID       = db.STREETs.FirstOrDefault(s => s.StreetName == tStreet_ID).ID,
                        District_ID     = db.DISTRICTs.FirstOrDefault(d => d.DistrictName == tDistrict_ID).ID,
                        Ward_ID         = db.WARDs.FirstOrDefault(d => d.WardName == tWard_ID).ID,
                        UnitPrice       = item["UnitPrice"].ToString(),

                        Price        = int.Parse(item["Price"].ToString()),
                        BathRoom     = int.Parse(item["Bathroom"].ToString()),
                        BedRoom      = int.Parse(item["Bedroom"].ToString()),
                        PackingPlace = int.Parse(item["PackingPlace"].ToString()),
                        Content      = item["Content"].ToString(),
                        Area         = "20m2",
                    };
                    //project.STREET = db.STREETs.Find(project.Street_ID);
                    // project.STREET.StreetName
                    _context.ReferenceDetails.Add(projects.Header.Contains("ID") ? item["ID"] : project.PropertyName, project);
                    db.PROPERTies.Add(project);
                }
                db.SaveChanges();
            }
        }
Example #5
0
        public ActionResult postProject(PROPERTY e, HttpPostedFileBase Avatar, List <string> chk1, List <HttpPostedFileBase> images)
        {
            if (Session["UserID"] == null)
            {
                return(View("Login"));
            }
            if (Avatar == null && !Avatar.ContentType.Contains("image"))
            {
                ModelState.AddModelError("Avatar", "chưa có Avatar");
            }
            //Avatar save file on webserver and sign value for model
            if (e.Content == null && e.PropertyName == null && e.Area == null && e.Price == 0 && Avatar == null)
            {
                return(View());
            }
            if (Avatar != null)
            {
                string avatar = "";
                if (Avatar.ContentLength > 0)
                {
                    var filename = Path.GetFileName(Avatar.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Images/"), filename);
                    Avatar.SaveAs(path);
                    avatar = filename;
                }
                e.Avatar = avatar;
            }

            //Image save file on webserver and add new PROPERTY_IMAGE into table PROPERTY_IMAGE
            foreach (HttpPostedFileBase img in images)
            {
                if (img != null)
                {
                    if (img.ContentLength > 0)
                    {
                        var filename = Path.GetFileName(img.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Images/"), filename);
                        img.SaveAs(path);
                        PROPERTY_IMAGE ppti = new PROPERTY_IMAGE();
                        ppti.Image       = filename;
                        ppti.Property_ID = e.ID;
                        m.PROPERTY_IMAGE.Add(ppti);
                    }
                }
                else
                {
                    break;
                }
            }

            //save PROPERTY_FEATURE into PROPERTY_FEATURE table foreach Feature
            if (chk1 != null)
            {
                foreach (string fe in chk1)
                {
                    PROPERTY_FEATURE profe = new PROPERTY_FEATURE();
                    profe.Feature_ID  = m.FEATUREs.SingleOrDefault(x => x.FeatureName == fe).ID;
                    profe.Property_ID = e.ID;
                    m.PROPERTY_FEATURE.Add(profe);
                }
            }
            e.Created_at  = DateTime.Now;
            e.Create_post = DateTime.Now;
            e.UserID      = int.Parse(Session["UserID"].ToString());
            e.Status_ID   = 1;

            m.PROPERTies.Add(e);
            m.SaveChanges();


            return(RedirectToAction("Index"));
        }
Example #6
0
        public ActionResult Delete(PROPERTY model)
        {
            PROPERTY pro   = db.PROPERTies.Find(model.ID);
            var      ftpr  = db.PROPERTY_FEATURE.Where(x => x.Property_ID == model.ID).ToList();
            var      image = db.PROPERTY_IMAGE.Where(x => x.Property_ID == model.ID).ToList();

            db.PROPERTY_IMAGE.RemoveRange(image);
            db.PROPERTY_FEATURE.RemoveRange(ftpr);
            db.PROPERTies.Remove(pro);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }