Esempio n. 1
0
 partial void DeleteObjects_LiveConditions(Objects_LiveConditions instance);
Esempio n. 2
0
 partial void UpdateObjects_LiveConditions(Objects_LiveConditions instance);
Esempio n. 3
0
 partial void InsertObjects_LiveConditions(Objects_LiveConditions instance);
Esempio n. 4
0
		private void detach_Objects_LiveConditions(Objects_LiveConditions entity)
		{
			this.SendPropertyChanging();
			entity.Objects = null;
		}
Esempio n. 5
0
		private void attach_Objects_LiveConditions(Objects_LiveConditions entity)
		{
			this.SendPropertyChanging();
			entity.LiveConditions = this;
		}
Esempio n. 6
0
        public ActionResult EditObjects(FormCollection coll)
        {
            dbDataContext db = new dbDataContext();
            int obj_id;
            try
            {
                obj_id = Int32.Parse(coll["obj_id"]);
            }
            catch
            {
                return RedirectToAction("ObjectsList");
            }

            Objects obj = db.Objects.SingleOrDefault(c=>c.ID==obj_id);
            if (obj == null)
            {
                return RedirectToAction("ObjectsList");
            }

            obj.type = Int32.Parse(coll["FlatType"]);
            obj.region_id = Int32.Parse(coll["Region"]);
            obj.header = coll["header"];
            obj.address = coll["address"];
            if (coll["rooms_count"] != String.Empty)
                obj.rooms_count = Int32.Parse(coll["rooms_count"]);
            else
                obj.rooms_count = 0;
            if (coll["guests_count"] != String.Empty)
                obj.guests_count = Int32.Parse(coll["guests_count"]);
            else
                obj.guests_count = 0;

            if (coll["price1"] != String.Empty)
                obj.price1 = Decimal.Parse(coll["price1"]);
            else obj.price1 = 0;

            if (coll["price2"] != String.Empty)
                obj.price2 = Decimal.Parse(coll["price2"]);
            else
                obj.price2 = 0;

            if (coll["price5"] != String.Empty)
                obj.price5 = Decimal.Parse(coll["price5"]);
            else obj.price5 = 0;
            if (coll["price14"] != String.Empty)
                obj.price14 = Decimal.Parse(coll["price14"]);
            else
                obj.price14 = 0;

            obj.desc_body = coll["desc"];

            //Записываем картинки

            HttpPostedFileBase file = Request.Files["large_foto1"];
            MemoryStream ms;
            Image img;
            Binary bin;

            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic1large = bin;
            }

            file = Request.Files["large_foto2"];
            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic2large = bin;
            }

            file = Request.Files["foto1"];
            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic1 = bin;
            }

            file = Request.Files["foto2"];
            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic2 = bin;
            }

            file = Request.Files["foto3"];
            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic3 = bin;
            }

            file = Request.Files["foto4"];
            if (file.ContentLength != 0)
            {
                ms = new MemoryStream();
                img = Image.FromStream(file.InputStream);
                img.Save(ms, img.RawFormat);
                bin = new Binary(ms.ToArray());
                obj.pic4 = bin;
            }//--Записываем картинки

            db.SubmitChanges();

            //Чистим таблицы- связки
            List<Objects_LiveConditions> olc_list = db.Objects_LiveConditions.Select(p => p).Where(p => p.object_id == obj.ID).ToList<Objects_LiveConditions>();
            foreach (Objects_LiveConditions olc in olc_list)
            {
                db.Objects_LiveConditions.DeleteOnSubmit(olc);
            }
            List<Objects_Attributes> oattr_list = db.Objects_Attributes.Select(p => p).Where(p => p.object_id == obj.ID).ToList<Objects_Attributes>();
            foreach (Objects_Attributes olc in oattr_list)
            {
                db.Objects_Attributes.DeleteOnSubmit(olc);
            }

            db.SubmitChanges();

            //Записываем жизненные условия
            var lcs = coll.AllKeys.Where(c => (c.StartsWith("lc_") & (!c.Contains("val"))));

            foreach (var attr in lcs)
            {
                string temp_key = attr.Replace("lc_", "lc_val_");
                string temp_value = coll[temp_key];
                Objects_LiveConditions olc = new Objects_LiveConditions();
                olc.lc_id = Int32.Parse(attr.Replace("lc_", ""));
                olc.object_id = obj.ID;
                olc._value = temp_value;
                db.Objects_LiveConditions.InsertOnSubmit(olc);
            }

            var attrs = coll.AllKeys.Where(c => (c.StartsWith("attr_")));

            foreach (var attr in attrs)
            {
                string temp_id = attr.Replace("attr_", "");
                Objects_Attributes oattr = new Objects_Attributes();
                oattr.attribute_id = Int32.Parse(temp_id);
                oattr.object_id = obj.ID;
                db.Objects_Attributes.InsertOnSubmit(oattr);
            }

            db.SubmitChanges();

            return RedirectToAction("ObjectsList");
        }