Ejemplo n.º 1
0
        public ActionResult EditDevice(ClientDeviceInfo cdi_cl)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    if (cdi_cl.deviceCategory == null)
                    {
                        cdi_cl.deviceCategory = TempData.Get <string>("deviceCategory");
                    }

                    /*
                     * if (cdi_cl.deviceSubcategory == null)
                     * {
                     *  cdi_cl.deviceSubcategory = TempData.Get<string>("deviceSubcategory");
                     * }
                     */

                    string timeToday = DateTime.Now.ToString("hh:mm:ss tt");
                    string dateToday = DateTime.Now.ToString("M/dd/yyyy");

                    //  even though it's a edit date, still keep it as a registration date
                    cdi_cl.deviceRegistrationDate = dateToday;
                    cdi_cl.deviceRegistrationTime = timeToday;

                    string client            = GetCurrentClaimValues.GetCurrentUserClient();
                    int    deviceAddedByUser = GetCurrentClaimValues.GetCurrentUserId();

                    cdi_cl.client            = client;
                    cdi_cl.deviceAddedByUser = deviceAddedByUser;

                    db.Entry(cdi_cl).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else
            {
                ModelState.AddModelError("", "Incorrect data has been entered");
            }

            if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN)
            {
                return(RedirectToAction("RegisteredDevices", "Admin"));
            }
            else
            {
                return(RedirectToAction("Index", "Registrar"));
            }
        }
 public ActionResult Index()
 {
     ViewBag.DefinedRoles = CommonManager.ReturnAvailableRoles();
     if (User.Identity.IsAuthenticated)
     {
         var huy = GetCurrentClaimValues.GetCurrentUserRole();
         if (GetCurrentClaimValues.GetCurrentUserRole() == ConstantValues.ROLE_AUTHORIZER)
         {
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         return(View());
     }
 }
Ejemplo n.º 3
0
        public ActionResult DeleteDevice(int id)
        {
            var db           = new MainDbContext();
            var neededDevice = db.clientDeviceInfo.Find(id);

            if (neededDevice == null)
            {
                return(HttpNotFound());
            }

            db.clientDeviceInfo.Remove(neededDevice);
            db.SaveChanges();

            if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN)
            {
                return(RedirectToAction("RegisteredDevices", "Admin"));
            }
            else
            {
                return(RedirectToAction("Index", "Registrar"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddNewDevice(ClientDeviceInfo cdi_cl)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    string timeToday         = DateTime.Now.ToString("HH:mm:ss");
                    string dateToday         = DateTime.Now.ToString("M/dd/yyyy");
                    string client            = GetCurrentClaimValues.GetCurrentUserClient();
                    int    deviceAddedByUser = GetCurrentClaimValues.GetCurrentUserId();

                    var device = db.clientDeviceInfo.Create();

                    device.client                 = client;
                    device.deviceAddedByUser      = deviceAddedByUser;
                    device.deviceRegistrationDate = dateToday;
                    device.deviceRegistrationTime = timeToday;

                    //  since it is an id for the purposes of cascading dropdowns
                    //int deviceCategoryId = Convert.ToInt32(cdi_cl.deviceCategory);
                    //var materializeDeviceCategory = db.deviceCategory.Where(c => c.deviceCategoryId == deviceCategoryId).Select(c => c.deviceCategoryName).ToList();
                    string deviceCategory = cdi_cl.deviceCategory;

                    device.deviceCategory = deviceCategory;
                    //device.deviceSubcategory = cdi_cl.deviceSubcategory;
                    device.deviceName = cdi_cl.deviceName;
                    device.deviceNUINTASerialNumber = cdi_cl.deviceNUINTASerialNumber;
                    device.deviceCarrier            = cdi_cl.deviceCarrier;
                    device.deviceCondition          = cdi_cl.deviceCondition;
                    device.deviceBin           = cdi_cl.deviceBin;
                    device.deviceRepairCost    = cdi_cl.deviceRepairCost;
                    device.deviceOtherComments = cdi_cl.deviceOtherComments;

                    //  since an admin would have a slightly different view when registering a device
                    if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN)
                    {
                        device.deviceUsedBy  = cdi_cl.deviceUsedBy;
                        device.deviceValue   = cdi_cl.deviceValue;
                        device.deviceSoldFor = cdi_cl.deviceSoldFor;
                    }

                    //Console.WriteLine(device);
                    db.clientDeviceInfo.Add(device);
                    db.SaveChanges();
                }
            }
            else
            {
                ModelState.AddModelError("", "Incorrect data has been entered");
            }

            return(RedirectToAction("RegisteredDevices"));

            //if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN)
            //{
            //    return RedirectToAction("Devices", "Admin");
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Registrar");
            //}
        }
        public ActionResult Index(string token)
        {
            string userAgent = Request.Headers["User-Agent"].ToString();
            bool   result    = CommonManager.IsTokenValid(token, CommonManager.GetIP(Request), userAgent);

            LoginStatus ls_cl = new LoginStatus()
            {
            };

            ls_cl.loginStatus = result;

            if (result == true)
            {
                LoginReturnUserBasicInfo lrubi = CommonManager.ReturnInfoAboutUser(token);
                ls_cl.lrubi = lrubi;
                ClaimsIdentity identity = new ClaimsIdentity();
                CommonData     cd       = CommonManager.ReturnInfoAboutCommonData(lrubi.userEmployer);
                if (lrubi.userType == "Admin")
                {
                    //  create an identity with name and role
                    identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, lrubi.userId),
                        new Claim(ClaimTypes.Role, lrubi.userType),
                        new Claim("userEmployer", lrubi.userEmployer.ToLower()),
                        new Claim("userUniqueDatabaseId", lrubi.userUniqueDatabaseId),
                        new Claim("userRole", lrubi.userType),
                        new Claim("sendgridEmail", cd.sendgridEmail),
                        new Claim("timezone", cd.timezone),
                        new Claim("cultureInfo", cd.cultureInfo),
                        new Claim("sendgridEmailAuthor", cd.sendgridEmailAuthor),
                        new Claim("phoneNumber", cd.phoneNumber),
                        new Claim("destination", cd.destination.ToLower()),
                        new Claim("destinationAirportCode", cd.destinationAirportCode),
                        new Claim("dateFormat", cd.dateFormat)
                    }, "CustomCookie");
                }
                else
                {
                    //  create an identity with name and role
                    identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, lrubi.userId),
                        new Claim(ClaimTypes.Role, lrubi.userType),
                        new Claim("userEmployer", lrubi.userEmployer.ToLower()),
                        new Claim("userUniqueDatabaseId", lrubi.userUniqueDatabaseId),
                        new Claim("userRole", lrubi.userType),
                        new Claim("timezone", cd.timezone),
                        new Claim("cultureInfo", cd.cultureInfo),
                        new Claim("destination", cd.destination.ToLower()),
                        new Claim("destinationAirportCode", cd.destinationAirportCode),
                        new Claim("dateFormat", cd.dateFormat)
                    }, "CustomCookie");
                }

                //  actually login with identity
                var ctx         = Request.GetOwinContext();
                var authManager = ctx.Authentication;
                authManager.SignIn(identity);

                var huy = GetCurrentClaimValues.GetCurrentUserRole();
                if (lrubi.userType == ConstantValues.ROLE_AUTHORIZER)
                {
                    ls_cl.successUrlAction = Url.Action("Index", "Home");
                }
                else
                {
                    ls_cl.successUrlAction = Url.Action("Index", "Home");
                    //return RedirectToAction("Index", "Home");
                }
            }

            return(Json(JsonConvert.SerializeObject(ls_cl), JsonRequestBehavior.AllowGet));
        }