Example #1
0
        public static ClsReturnValues setDriver(ClsDriver obj, Guid SessionID)
        {
            ClsReturnValues lst = new ClsReturnValues();

            using (var db = new tdoEntities())
            {

                lst = db.uspAddEditDriver(obj.driverID, obj.driverCode, obj.firstName, obj.middleName, obj.lastName, obj.createdByID, SessionID).FirstOrDefault();
            }
            return lst;
        }
        public JsonResult setDriver(string driverID, string driverCode, string firstName, string middleName, string lastName)
        {
            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(driverID) == 0 && !addableForms.Contains("Driver"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to add new records." });
            }
            else if (int.Parse(driverID) != 0 && !editableForms.Contains("Driver"))
            {
                return Json(new { id = 0, isSuccess = false, msg = "You are not allowed to edit records." });
            }

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

            Guid Session = new Guid(GetSession()); //do not hard code session ID and createdbyID
            int _id = 0;
            try { _id = int.Parse(driverID.Trim()); }
            catch { }
            ClsDriver obj = new ClsDriver()
            {
                driverID = _id,
                driverCode = driverCode,
                firstName = firstName,
                middleName = middleName,
                lastName = lastName,
                createdByID = GetID(),
                sessionID = Session
            };
            ClsReturnValues k = Administration.setDriver(obj, Session);
            return Json(new { id = k.ID, isSuccess = k.IsSuccess ?? false ? 1 : 0, msg = k.Response });
        }