Ejemplo n.º 1
0
        public ActionResult ToBook(Guid id)
        {
            if (TAuth.IsLogged() && !TAuth.IsAdmin())
            {
                var userID = (string)Session["UserID"];

                if (userID == null || id == null)
                {
                    return(RedirectToAction("Index"));
                }

                Spectacle spectacle = repo.GetSpectacle(id);
                User      user      = repo.GetUser(Guid.Parse(userID));

                Sale sale = new Sale
                {
                    ID          = Guid.Empty,
                    SpectacleID = spectacle.ID,
                    Spectacle   = spectacle,
                    UserID      = user.ID,
                    User        = user,
                    Amount      = 2
                };

                return(View(sale));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 2
0
        public JsonResult ToBookConfirm(string saleStr)
        {
            bool   success = false;
            string message = "There was an error";

            if (TAuth.IsLogged() && !TAuth.IsAdmin())
            {
                try
                {
                    Sale sale = JsonConvert.DeserializeObject <Sale>(saleStr);
                    sale.ID = Guid.Empty;

                    int ticketsCount = repo.GetSpectacle(sale.SpectacleID).TicketsCount;
                    int allSales     = repo.GetAllSales().Where(s => s.SpectacleID == sale.SpectacleID && s.State.Name == "Active").Sum(a => a.Amount);

                    if (sale.Amount <= ticketsCount - allSales)
                    {
                        repo.SaveSale(sale);

                        success = true;
                        message = "OK";
                    }
                    else
                    {
                        message = string.Format("We have not {0} tickets. We have {1}", sale.Amount, ticketsCount - allSales);
                    }
                }
                catch
                {
                }
            }

            return(Json(new { Success = success, Message = message }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
 public ActionResult Index()
 {
     if (TAuth.IsAdmin())
     {
         return(View(repo.GetAllSpectacles()));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 4
0
 public ActionResult DeleteUser(Guid id)
 {
     if (TAuth.IsAdmin())
     {
         return(View(repo.GetUser(id)));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 5
0
 public ActionResult GetSpectacle(Guid id)
 {
     if (TAuth.IsAdmin())
     {
         return(View(repo.GetSpectacle(id)));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 6
0
        public CommandResponse Execute()
        {
            var response = new CommandResponse()
            {
                Success = false
            };

            try
            {
                var item = db.Users.FirstOrDefault(w => w.ID == command.User.ID);

                if (item == null)
                {
                    item              = command.User;
                    item.ID           = Guid.NewGuid();
                    item.RegDate      = DateTime.Now;
                    item.PasswordHash = TAuth.Hash(item.PasswordHash);
                    item.State        = db.States.Where(s => s.Name == "Active").FirstOrDefault();
                    item.StateID      = db.States.Where(s => s.Name == "Active").FirstOrDefault().ID;

                    if (item.Role == null)
                    {
                        item.Role   = db.Roles.Where(r => r.Name == "User").FirstOrDefault();
                        item.RoleID = db.Roles.Where(r => r.Name == "User").FirstOrDefault().ID;
                    }
                    db.Users.Add(item);
                }
                else
                {
                    db.Entry(item);
                    item.Name    = command.User.Name;
                    item.Email   = command.User.Email;
                    item.RoleID  = command.User.RoleID;
                    item.StateID = command.User.StateID;
                    item.RegDate = command.User.RegDate;
                }

                db.SaveChanges();

                response.ID              = item.ID;
                response.Success         = true;
                response.ResponseObjects = new List <object>
                {
                    item.Name,
                    item.Role
                };
                response.Message = "Saved state.";
            }
            catch
            {
            }

            return(response);
        }
Ejemplo n.º 7
0
 public ActionResult AddState()
 {
     if (TAuth.IsAdmin())
     {
         return(View());
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 8
0
 public ActionResult DeleteConfirmed(Guid id)
 {
     if (TAuth.IsAdmin())
     {
         repo.DeleteNotification(id);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 9
0
        public ActionResult AddUser(User item)
        {
            if (TAuth.IsAdmin())
            {
                repo.SaveUser(item);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 10
0
        public ActionResult DeleteSale(Guid id)
        {
            if (TAuth.IsLogged() && !TAuth.IsAdmin())
            {
                repo.DeleteSale(id);

                return(RedirectToAction("UserAllInfo", new { id = Guid.Parse((string)Session["UserID"]) }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 11
0
        public ActionResult AddNotification(Notification item)
        {
            if (TAuth.IsAdmin())
            {
                repo.SaveNotification(item);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 12
0
        public ActionResult AddSpectacle(Spectacle item)
        {
            if (TAuth.IsAdmin())
            {
                repo.SaveSpectacle(item);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 13
0
        public ActionResult AddRole()
        {
            if (TAuth.IsAdmin())
            {
                ViewBag.StateID = new SelectList(repo.GetAllStates(), "ID", "Name");

                return(View());
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 14
0
        public ActionResult EditRole(Guid id)
        {
            if (TAuth.IsAdmin())
            {
                var role = repo.GetRole(id);

                ViewBag.StateID = new SelectList(repo.GetAllStates(), "ID", "Name", role.StateID);

                return(View(role));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 15
0
        public ActionResult EditUser(Guid id)
        {
            if (TAuth.IsAdmin())
            {
                var user = repo.GetUser(id);

                ViewBag.StateID = new SelectList(repo.GetAllStates(), "ID", "Name", user.StateID);
                ViewBag.RoleID  = new SelectList(repo.GetAllRoles(), "ID", "Name", user.RoleID);

                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 16
0
        public ActionResult EditNotification(Guid id)
        {
            if (TAuth.IsAdmin())
            {
                var notification = repo.GetNotification(id);

                ViewBag.StateID = new SelectList(repo.GetAllStates(), "ID", "Name", notification.StateID);
                ViewBag.UserID  = new SelectList(repo.GetAllUsers(), "ID", "Name", notification.UserID);

                return(View(notification));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 17
0
        public ActionResult EditSale(Guid id)
        {
            if (TAuth.IsAdmin())
            {
                var sale = repo.GetSale(id);

                ViewBag.UserID      = new SelectList(repo.GetAllUsers(), "ID", "Name", sale.UserID);
                ViewBag.SpectacleID = new SelectList(repo.GetAllSpectacles(), "ID", "Name", sale.SpectacleID);
                ViewBag.StateID     = new SelectList(repo.GetAllStates(), "ID", "Name", sale.StateID);

                return(View(sale));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 18
0
        public ActionResult UserAllInfo()
        {
            if (TAuth.IsLogged() && !TAuth.IsAdmin())
            {
                var user  = repo.GetUser(Guid.Parse((string)Session["UserID"]));
                var sales = repo.GetAllSales();

                UserAllInfoModel model = new UserAllInfoModel
                {
                    User  = user,
                    Sales = sales.Where(s => s.UserID == user.ID && s.State.Name == "Active").ToList()
                };

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 19
0
        public JsonResult LogIn(string userStr)
        {
            bool   success = false;
            string message = "There was an error";

            try
            {
                User user   = JsonConvert.DeserializeObject <User>(userStr);
                User dbUser = repo.GetUserByEmail(user.Email);
                if (dbUser == null)
                {
                    message = "User with e-mail/password was not found";
                }
                else
                {
                    if (TAuth.Hash(user.PasswordHash) == dbUser.PasswordHash)
                    {
                        Session["User"]     = dbUser;
                        Session["UserID"]   = dbUser.ID.ToString();
                        Session["UserName"] = dbUser.Name;
                        Session["Role"]     = dbUser.Role.Name;

                        success = true;
                        message = "OK";
                    }
                    else
                    {
                        message = "User with e-mail/password was not found";
                    }
                }
            }
            catch
            {
            }

            return(Json(new { Success = success, Message = message }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 20
0
 public Container(TToken token, TAuth data)
 {
     Token = token;
     Data  = data;
 }