Esempio n. 1
0
        public virtual ActionResult SaveSuccess(City city, Street street,IEnumerable<int> LayoutDislocationDelete,
            [ModelBinder(typeof(CustomModelBinderForSegment))] ICollection<Segment> segment,
            [ModelBinder(typeof(CustomModelBinderForRM))] ICollection<SpecificationofRM> SpecificationofRM,
            [ModelBinder(typeof(CustomModelBinderForRS))] ICollection<SpecificationofRS> SpecificationofRS,
            [ModelBinder(typeof(CustomModelBinderForRB))] ICollection<SpecificationOfRb> SpecificationofRB,
            HttpPostedFileBase layoutScheme = null, [ModelBinder(typeof(CustomModelBinderForlayoutDislocation))] List<ModelLayoutDislocation> layoutDislocation = null)
        {
            logger.Info("Пользователь {0} создал улицу {1}",User.Identity.Name,street.Name);

            int LastIndexSegment;
            if (db.Segment.Any())
            {
                LastIndexSegment = db.Segment.AsEnumerable().Last().id;
            }
            else
            {
                LastIndexSegment = 0;
            }
            var streetInfo = new Street()
            {
                Name = street.Name,
                BreadthS = street.BreadthS,
                BreadthE = street.BreadthE,
                LengthE = street.LengthE,
                LengthS = street.LengthS,
                City_id = city.id,
                UniqueNumber = TableAdapterExtensions.StringSymvol()
            };

            db.Street.Add(streetInfo);
            AjaxMinExtensions.ForEach(segment.GroupBy(a => a.Name), a => AjaxMinExtensions.ForEach(a, b => b.id = ++LastIndexSegment));
            streetInfo.Segment = segment;
            streetInfo.SpecificationofRM = SpecificationofRM;
            foreach (var instance in SpecificationofRM)
            {
                if (db.TheHorizontalRoadMarking.Any(a => a.NumberMarking == instance.TheHorizontalRoadMarkingIdModel))
                {
                    try
                    {
                        instance.TheHorizontalRoadMarkingId =
                            db.TheHorizontalRoadMarking.Single(
                                a => a.NumberMarking == instance.TheHorizontalRoadMarkingIdModel).id;
                    }
                    catch
                    {
                    }
                }
            }

            db.Segment.AddRange(segment);


            if (layoutScheme != null)
            {
                layoutScheme imageScheme = new layoutScheme();
                imageScheme.ImageMimeType = layoutScheme.ContentType;
                imageScheme.ImageData = new byte[layoutScheme.ContentLength];
                imageScheme.Id = streetInfo.id;
                layoutScheme.InputStream.Read(imageScheme.ImageData, 0, layoutScheme.ContentLength);
                db.layoutSchemes.Add(imageScheme);
            }

            AjaxMinExtensions.ForEach(SpecificationofRS, a =>
            {
                a.RoadSignsId =
                    db.RoadSigns.Single(b => b.NumberRoadSigns == a.RoadSignsIdModel).id;
                a.SegmentId = segment.Single(c => c.Name == a.SegmentIdModel).id;
                a.Street_id = streetInfo.id;

            });
            if (layoutDislocation != null)
            {
                List<layoutDislocation> imageDislocations = new List<layoutDislocation>();
                layoutDislocation imageDislocation;
                layoutDislocation.ForEach(a =>
                {
                    imageDislocation = new layoutDislocation();
                    imageDislocation.ImageMimeType = a.File.ContentType;
                    imageDislocation.ImageData = new byte[a.File.ContentLength];
                    a.File.InputStream.Read(imageDislocation.ImageData, 0, a.File.ContentLength);
                    imageDislocation.StreetId = streetInfo.id;
                    imageDislocation.SegmentId = segment.Single(c => c.Name == a.SegmentId).id;
                    imageDislocations.Add(imageDislocation);
                }
                    );
                db.layoutDislocations.AddRange(imageDislocations);
            }
            AjaxMinExtensions.ForEach(SpecificationofRB, a =>
            {
                a.RoadBarriersId =
                    db.RoadBarriers.Single(b => b.NumberBarriers == a.RoadBarriersIdModel).Id;
                a.SegmentId = segment.Single(c => c.Name == a.SegmentIdModel).id;
                a.StreetId = streetInfo.id;

            });
            db.SpecificationOfRb.AddRange(SpecificationofRB);
            db.SpecificationofRM.AddRange(SpecificationofRM);
            db.SpecificationofRS.AddRange(SpecificationofRS);
            db.SaveChanges();
            return RedirectToAction("Table");
        }
Esempio n. 2
0
        public virtual ActionResult EditStreets(
            City city, Street street, IEnumerable<int> LayoutDislocationDelete,
            [ModelBinder(typeof(CustomModelBinderForSegment))] ICollection<Segment> segment,
            [ModelBinder(typeof(CustomModelBinderForRM))] ICollection<SpecificationofRM> SpecificationofRM,
            [ModelBinder(typeof(CustomModelBinderForRS))] ICollection<SpecificationofRS> SpecificationofRS,
            [ModelBinder(typeof(CustomModelBinderForRB))] ICollection<SpecificationOfRb> SpecificationofRB,
            HttpPostedFileBase layoutScheme = null, [ModelBinder(typeof(CustomModelBinderForlayoutDislocation))] List<ModelLayoutDislocation> layoutDislocation = null)
        {

            int LastIndexSegment = street.id;
            Street streetForUniqueNumber = db.Street.Find(street.id);
            var streetInfo = new Street()
            {
                Name = street.Name,
                BreadthS = street.BreadthS,
                BreadthE = street.BreadthE,
                LengthE = street.LengthE,
                LengthS = street.LengthS,
                City_id = city.id,
                UniqueNumber = streetForUniqueNumber.UniqueNumber
            };
            List<layoutDislocation> OldLayoutDislocation =
             db.layoutDislocations.Include("Segment").AsEnumerable().Where(a => a.StreetId == streetForUniqueNumber.id).
             Select(a => new layoutDislocation()
             {
                 Id = a.Id,
                 ImageData = a.ImageData,
                 ImageMimeType = a.ImageMimeType,
                 SegmentName = a.Segment.Name
             }).ToList();
            if (LayoutDislocationDelete != null)
            {
                foreach (var item in OldLayoutDislocation.ToList())
                {
                    if (!LayoutDislocationDelete.Contains(item.SegmentName))
                    {
                        OldLayoutDislocation.Remove(item);
                    }
                }
            }
            layoutScheme OdllayoutScheme =
                db.layoutSchemes.Include("Street").AsEnumerable().SingleOrDefault(a => a.Id == streetForUniqueNumber.id);

            DeleteDataStreet(street.id, true);

            if (OdllayoutScheme != null)
            {
                OdllayoutScheme.Id = streetInfo.id;
                OdllayoutScheme.Street = null;
            }
            var newstreet = db.Street.Add(streetInfo);
            db.SaveChanges();

            if (OdllayoutScheme != null)
                OdllayoutScheme.Id = newstreet.id;

            AjaxMinExtensions.ForEach(segment.GroupBy(a => a.Name), a => AjaxMinExtensions.ForEach(a, b =>
            {
                b.id = ++LastIndexSegment;
                b.Street_id = newstreet.id;
            }));

            SpecificationofRM.ToList().ForEach(a => a.StreetId = newstreet.id);
            var newsegment = db.Segment.AddRange(segment);

            foreach (var instance in SpecificationofRM)
            {
                if (db.TheHorizontalRoadMarking.Any(a => a.NumberMarking == instance.TheHorizontalRoadMarkingIdModel))
                {
                    try
                    {
                        instance.TheHorizontalRoadMarkingId =
                            db.TheHorizontalRoadMarking.Single(
                                a => a.NumberMarking == instance.TheHorizontalRoadMarkingIdModel).id;
                    }
                    catch
                    {
                    }
                }
            }


            if (layoutScheme != null)
            {
                layoutScheme imageScheme = new layoutScheme();
                imageScheme.ImageMimeType = layoutScheme.ContentType;
                imageScheme.ImageData = new byte[layoutScheme.ContentLength];
                imageScheme.Id = newstreet.id;
                layoutScheme.InputStream.Read(imageScheme.ImageData, 0, layoutScheme.ContentLength);
                db.layoutSchemes.Add(imageScheme);
            }
            else
            {
                if (OdllayoutScheme != null)
                {
                    db.layoutSchemes.Add(OdllayoutScheme);
                }
            }


            List<layoutDislocation> imageDislocations = new List<layoutDislocation>();
            layoutDislocation imageDislocation;

            if (layoutDislocation.Count != 0 || OldLayoutDislocation.Count != 0)
            {

                if (OldLayoutDislocation.Count != 0)
                {
                    foreach (var item in OldLayoutDislocation)
                    {

                        if (layoutDislocation.Count != 0 && layoutDislocation.Any(a => a.SegmentId != item.SegmentName))
                        {
                            item.StreetId = streetInfo.id;
                            item.SegmentId = segment.Single(c => c.Name == item.SegmentName).id;
                            imageDislocations.Add(item);

                        }

                    }
                }
                if (layoutDislocation.Count != 0)
                {
                    layoutDislocation.ForEach(a =>
                    {
                        imageDislocation = new layoutDislocation();
                        imageDislocation.ImageMimeType = a.File.ContentType;
                        imageDislocation.ImageData = new byte[a.File.ContentLength];
                        a.File.InputStream.Read(imageDislocation.ImageData, 0, a.File.ContentLength);
                        imageDislocation.StreetId = streetInfo.id;
                        imageDislocation.SegmentId = segment.Single(c => c.Name == a.SegmentId).id;
                        imageDislocations.Add(imageDislocation);
                    }
                        );
                }
                else
                {
                    if (OldLayoutDislocation.Count != 0)
                    {
                        foreach (var item in OldLayoutDislocation)
                        {
                            item.StreetId = streetInfo.id;
                            item.SegmentId = segment.Single(c => c.Name == item.SegmentName).id;
                            imageDislocations.Add(item);

                        }
                    }
                }

            }
            db.layoutDislocations.AddRange(imageDislocations);

            AjaxMinExtensions.ForEach(SpecificationofRB, a =>
            {
                a.RoadBarriersId =
                    db.RoadBarriers.Single(b => b.NumberBarriers == a.RoadBarriersIdModel).Id;
                a.SegmentId = segment.Single(c => c.Name == a.SegmentIdModel).id;
                a.StreetId = streetInfo.id;

            });
            AjaxMinExtensions.ForEach(SpecificationofRS, a =>
            {
                a.RoadSignsId =
                    db.RoadSigns.Single(b => b.NumberRoadSigns == a.RoadSignsIdModel).id;
                a.SegmentId = newsegment.Single(c => c.Name == a.SegmentIdModel).id;
                a.Street_id = streetInfo.id;

            });
            db.SpecificationOfRb.AddRange(SpecificationofRB);

            db.SpecificationofRM.AddRange(SpecificationofRM);

            db.SpecificationofRS.AddRange(SpecificationofRS);

            db.SaveChanges();

            return RedirectToAction("Table");
        }