Ejemplo n.º 1
0
        // save with EF context procedure : not currently used
        private bool saveCoordinatesWithProcedure()
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            DataContext contextForProcedure = new DataContext();

            contextForProcedure.Configuration.AutoDetectChangesEnabled = false;
            Polygons poly = Polygons.GetInstance();

            for (int i = 0; i < poly.Coords.Count; i++)
            {
                ObjectParameter success = new ObjectParameter("success", typeof(bool));
                ObjectParameter errMsg  = new ObjectParameter("errMsg", typeof(string));

                //ObjectResult<sp_insert_coordinates_Result> rslt = contextForProcedure.sp_insert_coordinates(poly.Coords[i].eventId,
                //    (int)poly.Coords[i].placeId, poly.Coords[i].seqCoordinate, poly.Coords[i].y, poly.Coords[i].x,
                //    success, errMsg);

                //rslt.Dispose();
                //rslt.ToList();
                if (Convert.ToBoolean(success.Value) == true)
                {
                    return(false);
                }
            }

            contextForProcedure.Configuration.AutoDetectChangesEnabled = false;

            return(true);
        }
Ejemplo n.º 2
0
        public ActionResult SaveParsedObjects(int eventId, List <string> styleInfo)
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            string errMsg = "Please check input information";
            bool   ret    = styleInfo == null ? false :
                            styleInfo.Count == 0 ? false :
                            verifyTypeAndStyle(styleInfo, out errMsg);

            // if succed deletion, process insertion.
            if (ret && DeleteEventObjects(eventId))
            {
                Polygons poly = Polygons.GetInstance();
                // save styleUrl
                MySqlBulkInsert.InsertStyleUrl(poly, eventId);

                //  -> retrieve styleUrl to link type's styleUrl
                poly.AddStyle(styles.GetQueryable().Where(x => x.idIPMEvent == eventId).ToList());

                // set type's styleUrl
                updateType_idStyleUrl(eventId, styleInfo);

                //  -> retrieve siteType to link placeinmap's siteType
                poly.AddType(types.GetQueryable().Where(x => x.idIPMEvent == eventId).ToList());

                //  -> build site's siteType
                poly.MakeSiteRelation(eventId);

                // save placeinmap
                MySqlBulkInsert.InsertPlaceInMap(poly, eventId);

                //  -> retrieve placeinmap to link coordinate's placeinmap
                poly.AddSite(places.GetQueryable().Where(x => x.idIPMEvent == eventId).ToList());

                // set coord's placeId
                poly.SetPlaceIdInCoords();

                // save coordinates
                MySqlBulkInsert.InsertCoordinates(poly);

                //  -> retrieve coordinate to change init=true
                poly.AddCoordinates(coords.GetQueryable().Where(x => x.idIPMEvent == eventId).ToList());

                // update placeinmap with isRVSite
                MySqlBulkInsert.UpdateIsRVSite_PlaceInMap(poly);

                //poly.Initialized = true;
                //poly.eventId = eventId;

                // reset msg with no error
                errMsg = "";
            }

            // return
            return(Json(new
            {
                success = ret,
                msg = errMsg
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        // save with Entity Framework : not currently used
        private bool saveCoordinatesWithEF()
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            //coords.SetAutoDetectChange(false);
            Polygons poly = Polygons.GetInstance();

            for (int i = 0; i < poly.Coords.Count; i++)
            {
                coordinate c = new coordinate();
                c.idIPMEvent    = poly.Coords[i].eventId;
                c.idPlaceInMap  = poly.Coords[i].placeId;
                c.seqCoordinate = poly.Coords[i].seqCoordinate;
                c.longitude     = poly.Coords[i].y;
                c.latitude      = poly.Coords[i].x;
                c.createDate    = DateTime.Now;
                c.lastUpdate    = DateTime.Now;

                coords.Insert(c);
                if ((i + 1) % 20 == 0)
                {
                    coords.Commit();
                }
                //break;
            }
            coords.Commit();

            //coords.SetAutoDetectChange(true);

            return(true);
        }
Ejemplo n.º 4
0
        // method for delete type & rate
        public ActionResult DeleteTypeRate(long eventId, long serviceId, string service, long sizeId, string size)
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            bool   ret    = true;
            string errMsg = "";

            Polygons poly = Polygons.GetInstance();

            if (!poly.DeleteTypeRate(eventId, serviceId, sizeId))
            {
                var _type = types.GetQueryable().Where(x => x.idIPMEvent == eventId && x.idService == serviceId && x.idSiteSize == sizeId).FirstOrDefault <sitetype>();
                if (_type == null || !delete_sitetype_dependants(_type.ID)
                    )
                {
                    ret    = false;
                    errMsg = string.Format("Type( service{0}, size{1}) : deletion Failed", service, size);
                }
            }

            return(Json(new
            {
                success = ret,
                msg = errMsg
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        // method for temporary type & rate
        public ActionResult AddTypeRate(long eventId, long serviceId, string service, long sizeId, string size, decimal week,
                                        decimal day)
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            bool     ret    = true;
            string   errMsg = "";
            Polygons poly   = Polygons.GetInstance();

            // check validation in terms of key
            //  1. check with table records
            var _type = types.GetQueryable().Where(x => x.idIPMEvent == eventId && x.idService == serviceId && x.idSiteSize == sizeId).FirstOrDefault <sitetype>();

            if (_type != null ||
                poly.TypeRates.Where(x => x.eventId == eventId && x.serviceId == serviceId && x.sizeId == sizeId).FirstOrDefault <sitetype_service_rate_view>() != null)
            {
                ret    = false;
                errMsg = string.Format("Same siteType with service({0}) and size({1}) is already exists!!", service, size);
            }

            if (ret)
            {
                poly.AddTypeRate(eventId, serviceId, service, sizeId, size, week, day);
            }

            return(Json(new
            {
                success = ret,
                msg = errMsg
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public ActionResult IPMEventMap()
        {
            SessionService sessionService = new SessionService(
                this.sessions,
                this.customers
                );

            long sessionID = sessionService.GetSessionID(this.HttpContext);
            long eventId   = sessionService.GetSessionIPMEventID(sessionID);

            //long eventId = events.GetQueryable().Select(x => x.ID).DefaultIfEmpty().Max();
            var      year = events.GetQueryable().Where(x => x.ID == eventId).FirstOrDefault <ipmevent>().year;
            Polygons poly = Polygons.GetInstance();

            resetPolygons(poly, eventId, year);
            // in case of no event
            if (poly._leftTop != null)
            {
                ViewBag.Lat = (poly._leftTop._x + poly._rightBottom._x) / 2;
                ViewBag.Lng = (poly._leftTop._y + poly._rightBottom._y) / 2;
            }
            else
            {
                ViewBag.Lat = 0;
                ViewBag.Lng = 0;
            }

            return(View(poly));
        }
Ejemplo n.º 7
0
        public ActionResult RefreshMap()
        {
            long     sessionID = sessionService.GetSessionID(this.HttpContext, true, true);
            Polygons poly      = Polygons.GetInstance();

            poly.Reset();

            return(RedirectToAction("Menu", "Login"));
        }
Ejemplo n.º 8
0
        // view for mapping between type and styleurl
        public ActionResult DigitizeMap()
        {
            Polygons poly = Polygons.GetInstance();

            poly.Reset();

            var model = events.GetAll();
            var year  = model.Max(x => x.year);

            ViewBag.year    = year;
            ViewBag.eventId = model.Where(x => x.year == year).First <ipmevent>().ID;
            return(View(model));
        }
Ejemplo n.º 9
0
        // partial view of DigitizeMap()
        public ActionResult SiteUrl(long eventId)
        {
            Polygons poly = Polygons.GetInstance();

            if (poly.Styles.Count == 0 || poly.Styles[0].eventId != eventId)
            {
                poly.AddStyle(styles.GetQueryable().Where(x => x.idIPMEvent == eventId).OrderByDescending(x => x.ID).ToList());
            }
            var _urls = poly.Styles.Where(x => x.eventId == eventId).ToList();

            ViewBag.styleCount = _urls.Count;
            ViewBag.eventId    = eventId;
            ViewBag.types      = typeRates.GetQueryable().Where(x => x.eventId == eventId).ToList();

            return(PartialView("SiteUrl", _urls));
        }
Ejemplo n.º 10
0
        // partial view of IPMEventInfo()
        public ActionResult SiteTypes(long year, long eventId)
        {
            var tRates = typeRates.GetQueryable().Where(x => x.eventId == eventId).ToList();

            // Try to get in memory sitetype_service_rate_view from poly for staff to continue to edit type
            Polygons poly = Polygons.GetInstance();

            poly.GetTypeRates(tRates, eventId);
            ViewBag.eventId = eventId;

            // send size, service
            ViewBag.sizes        = sizes.GetAll();
            ViewBag.services     = services.GetAll();
            ViewBag.eventStarted = isEventStarted(year);

            return(PartialView("SiteTypes", tRates));
        }
Ejemplo n.º 11
0
        // syleInfo string -> comma separated parameter (styleUrl, idService, idSize ), e.g., "#ffffffff,1,2"
        private bool verifyTypeAndStyle(List <string> styleInfo, out string errMsg)
        {
            errMsg = "";

            // check if a staff did not upload KML file
            Polygons poly = Polygons.GetInstance();

            if (poly.Sites.Count == 0 ||
                poly.Coords.Count == 0)
            {
                errMsg = "Upload KML File before Saving!!";
                return(false);
            }
            // no matching check
            if (styleInfo == null)
            {
                errMsg = "Insert all matching information";
                return(false);
            }

            // duplication check & 0 id
            List <string> dupcheck = new List <string>();

            foreach (var s in styleInfo)
            {
                string size_service = s.Split(',')[1] + s.Split(',')[2];
                // data duplication check
                if (dupcheck.Exists(x => x == size_service))
                {
                    errMsg = "Same type is choosed";
                    return(false);
                }
                // valid id check
                if (s.Contains(",0"))
                {
                    errMsg = "Type was not choosed";
                    return(false);
                }
                dupcheck.Add(size_service);
            }

            return(true);
        }
Ejemplo n.º 12
0
        // view for mapping between type and styleurl
        public ActionResult DigitizeMap(long eventId = -1)
        {
            Polygons poly = Polygons.GetInstance();

            poly.Reset();

            var model = events.GetAll();

            if (eventId == -1)
            {
                eventId = model.Where(x => x.year == (DateTime.Now.Year + 1)).First <ipmevent>().ID;
            }
            ViewBag.eventId = eventId;
            var year = model.Where(m => m.ID == eventId).First <ipmevent>().year;

            ViewBag.year = year;

            return(View(model));
        }
Ejemplo n.º 13
0
        // Fetch latest site update information => core part of map display
        public ActionResult GetSiteUpdate(string lastUpdate)
        {
            Polygons poly = Polygons.GetInstance();

            return(Json(poly.GetSiteUpdate(lastUpdate), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 14
0
        // method for database saving type & rate
        public ActionResult VerifyAndSaveTypes(string year, string city, string province, string street,
                                               DateTime startDate, DateTime endDate, DateTime lastDateRefund)
        {
            long sessionID = sessionService.GetSessionID(this.HttpContext, true, true);

            bool   ret    = true;
            string errMsg = "";
            long   _year  = 0;

            long.TryParse(year, out _year);

            /// parameter validation
            // dates check
            if (startDate == null || endDate == null || lastDateRefund == null ||
                startDate > endDate || lastDateRefund > endDate)
            {
                ret    = false;
                errMsg = string.Format("Please check Event Period");
            }
            // city, street check
            else if (city == string.Empty || street == string.Empty)
            {
                ret    = false;
                errMsg = string.Format("Please check city or street, it needs input");
            }

            /// event validation
            var _event = events.GetQueryable().Where(x => x.year == _year).FirstOrDefault <ipmevent>();
            var _found = _event != null ? true : false;

            if (ret && _found)
            {
                if (isEventStarted(_year))
                {
                    ret    = false;
                    errMsg = string.Format("Could not update this event which has been started");
                }
            }

            // validation of types are not needed due to AddTypeRate()
            if (ret == true)
            {
                if (!_found)
                {
                    _event = new ipmevent();
                }

                // update event object
                _event.year           = _year;
                _event.street         = street;
                _event.city           = city;
                _event.provinceCode   = province;
                _event.startDate      = startDate;
                _event.endDate        = endDate;
                _event.lastUpdate     = DateTime.Now;
                _event.lastDateRefund = lastDateRefund;

                if (_found)
                {
                    events.Update(_event);
                }
                else
                {
                    events.Insert(_event);
                }

                long eventId = _event.ID;

                // commit events
                events.Commit();
                // save all type and rate information
                Polygons poly = Polygons.GetInstance();

                foreach (var t in poly.TypeRates)
                {     // save new type
                    var _type = new sitetype
                    { // get eventId from event object not from TypeRates
                        idIPMEvent = _event.ID,
                        idSiteSize = t.sizeId,
                        idService  = t.serviceId,
                        createDate = DateTime.Now,
                        lastUpdate = DateTime.Now
                    };
                    types.Insert(_type);
                    types.Commit();
                    // save two rate with new type id
                    rates.Insert(new siterate
                    {
                        idSiteType = _type.ID,
                        period     = "Weekly",
                        rate       = (decimal)t.week,
                        createDate = DateTime.Now,
                        lastUpdate = DateTime.Now,
                        idIPMEvent = _event.ID
                    });
                    rates.Insert(new siterate
                    {
                        idSiteType = _type.ID,
                        period     = "Daily",
                        rate       = (decimal)t.day,
                        createDate = DateTime.Now,
                        lastUpdate = DateTime.Now,
                        idIPMEvent = _event.ID
                    });
                    rates.Commit();
                }

                // clear poly's TypeRates
                poly.TypeRates.Clear();
            }

            // return
            return(Json(new
            {
                success = ret,
                msg = errMsg
            }, JsonRequestBehavior.AllowGet));
        }