예제 #1
0
        public IActionResult GetUsers()
        {
            string email    = Request.Headers["Email"];
            string password = Request.Headers["Password"];

            if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(password))
            {
                return(BadRequest(_itemHelper.response(false, 500, "User can not authenticate please check email and password")));
            }

            UserManager user = _userManagerService.AuthenticateUser(email, password);

            if (user == null)
            {
                return(BadRequest(_itemHelper.response(false, 500, "User model is empty")));
            }

            CommonEnum.UserRoleType roletype = (CommonEnum.UserRoleType)Enum.Parse(typeof(CommonEnum.UserRoleType), user.RoleManager.Name);

            if (roletype != CommonEnum.UserRoleType.admin)
            {
                return(BadRequest(_itemHelper.response(false, 500, "You dont have right's to update entries")));
            }

            var userList = _userManagerService.GetAllUsers();

            //var jsonData = JsonConvert.SerializeObject(roleList);

            return(Ok(userList));
        }
        public ActionResult Login(UserLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userManagerService.AuthenticateUser(model.Email, model.Password);
                if (user != null)
                {
                    user.RoleManager = _roleManagerService.GetRoleById(user.RoleId);

                    HttpContext.Session.SetInt32("RoleId", user.RoleId);
                    HttpContext.Session.SetString("EmailId", model.Email);
                    HttpContext.Session.SetInt32("CreatorId", user.Id);

                    return(RedirectToAction("List", "Item"));
                }
                model.Message = "User can not auhthenticate";
            }
            return(View(model));
        }
예제 #3
0
        public IActionResult Create([FromBody] ItemCreateEditModel itemModel)
        {
            string          email           = Request.Headers["Email"];
            string          password        = Request.Headers["Password"];
            ItemReturnModel itemReturnModel = new ItemReturnModel();

            itemReturnModel.PicturesPath  = new List <string>();
            itemReturnModel.DocumentsPath = new List <string>();

            //StatusResponse response = new StatusResponse();

            //add pictures
            //itemModel.PictureBinary = itemModel.PictureBinary.Replace("data:image/png|tiff|jpg|gif;base64,", "");
            //byte[] picture = Convert.FromBase64String(itemModel.PictureBinary);

            try
            {
                if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(password))
                {
                    return(BadRequest(_itemHelper.response(false, 401, "Email or Password is empty")));
                }

                UserManager user = _userManagerService.AuthenticateUser(email, password);

                if (user == null)
                {
                    return(BadRequest(_itemHelper.response(false, 401, "User can not authenticate please check email and password")));
                }

                CommonEnum.UserRoleType roletype = (CommonEnum.UserRoleType)Enum.Parse(typeof(CommonEnum.UserRoleType), user.RoleManager.Name);

                if (roletype != CommonEnum.UserRoleType.admin)
                {
                    return(BadRequest(_itemHelper.response(false, 401, "User not have access for create item")));
                }

                //Generate QR code
                if (!String.IsNullOrEmpty(itemModel.Name))
                {
                    Guid fileName = Guid.NewGuid();
                    itemModel.QrCodePath = _itemHelper.QrProcess(itemModel.Name, Convert.ToString(fileName));
                }

                //Assign model data to entity
                Items item = _itemHelper.ModelToEntity(itemModel, user.Id, new Items());

                _itemsService.InsertItem(item);


                //Insert Pictures
                if (itemModel.Pictures.Count > 0)
                {
                    _itemHelper.InsertPictures(item.Id, user.Id, itemModel, itemReturnModel);
                }
                //Insert Documents
                if (itemModel.Documents.Count > 0)
                {
                    _itemHelper.InsertDocuments(item.Id, user.Id, itemModel, itemReturnModel);
                }

                itemReturnModel.Id         = item.Id;
                itemReturnModel.QrCodePath = item.QrCodePath;

                itemReturnModel.Status     = true;
                itemReturnModel.StatusCode = 201;

                return(Ok(itemReturnModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(_itemHelper.response(false, 504, "Internal server error")));
            }
        }