Ejemplo n.º 1
0
        public static ClsReturnValues setLocation(ClsLocation obj, Guid SessionID)
        {
            ClsReturnValues lst = new ClsReturnValues();

            using (var db = new tdoEntities())
            {

                lst = db.uspAddEditLocation(obj.locationID, obj.locationName, obj.regionID, obj.createdByID, SessionID).FirstOrDefault();
            }
            return lst;
        }
        public JsonResult setLocation(string locationID, string locationName, string regionID)
        {
            List<ClsUserDisplay> userDisplay = new List<ClsUserDisplay>();
            using (tdoEntities db = new tdoEntities())
            {
                userDisplay = db.uspGetUserDisplay(GetID()).ToList<ClsUserDisplay>();
            }
            List<string> editableForms = Restriction.GetEditableForms(userDisplay);
            List<string> addableForms = Restriction.GetAddableForms(userDisplay);

            if (int.Parse(locationID) == 0 && !addableForms.Contains("Location"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to add new records." });
            }
            else if (int.Parse(locationID) != 0 && !editableForms.Contains("Location"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to edit records." });
            }

            if (locationID == "") { locationID = "0"; }

            Guid Session = new Guid(GetSession()); //do not hard code session ID and createdbyID
            int _id = 0;
            try { _id = int.Parse(locationID.Trim()); }
            catch { }
            ClsLocation obj = new ClsLocation()
            {
                locationID = _id,
                locationName = locationName,
                regionID = int.Parse(regionID),
                createdByID = GetID(),
                sessionID = Session
            };
            ClsReturnValues k = Administration.setLocation(obj, Session);
            return Json(new { id = k.ID, isSuccess = k.IsSuccess ?? false ? 1 : 0, msg = k.Response });
        }