// GET: Admin/Accounts public ActionResult Index(LoginViewModel model) { try { ViewBag.Username = Session["Username"]; IUserService userService = this.Service <IUserService>(); if (Session["Username"] == null) { return(this.Redirect("/")); } User user = userService.GetByUsername(Session["Username"].ToString()); ILicienseService licienseService = this.Service <ILicienseService>(); Liciense liciense = licienseService.getIsUseLiciense(user.Id); ViewBag.licienseType = "Tài khoản quản lý"; ViewBag.UserFullName = user.Fullname; IDeviceService deviceService = this.Service <IDeviceService>(); IQueryable <User> userTotal = userService.GetAllUser(); ViewBag.TotalAccount = userTotal.Count(); ViewBag.TotalDevice = deviceService.GetActive().Count(); DateTime bt = (DateTime)user.Birthday; //ViewBag.BirthDay = String.Format("{0:dd/MM/yyyy}", bt); } catch (Exception e) { throw new Exception(e.Message); } return(View(model)); }
public HttpResponseMessage Get(string username, string password) { try { IUserService userService = this.Service <IUserService>(); ILicienseService licenseService = this.Service <ILicienseService>(); User user = userService.GetByUsernameAndPassword(username, password); if (user != null) { int checkDate = DateTime.Now.CompareTo(user.ExpireDate); Liciense licenseModel = licenseService.getIsUseLiciense(user.Id); if (checkDate <= 0 && licenseModel != null) { UserViewModel model = new UserViewModel() { Id = user.Id, Username = user.Username, Password = user.Password, Birthday = user.Birthday, Fullname = user.Fullname, RoleId = user.RoleId, Active = user.Active, ExpireDate = user.ExpireDate, PackageId = licenseModel.PackageId, }; return(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new JsonContent(model) }); } else { return(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.ExpectationFailed, Content = new JsonContent("Expired ") }); } } return(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.Unauthorized, Content = new JsonContent("Unauthorized"), }); } catch (Exception e) { return(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.BadRequest, Content = new JsonContent(e.Message) }); } }
// GET: Admin/Accounts public ActionResult Index(LoginViewModel model) { try { ViewBag.Username = Session["Username"]; IUserService userService = this.Service <IUserService>(); if (Session["Username"] == null) { return(this.Redirect("/")); } User user = userService.GetByUsername(Session["Username"].ToString()); ILicienseService licienseService = this.Service <ILicienseService>(); Liciense liciense = licienseService.getIsUseLiciense(user.Id); ViewBag.licienseType = "Tài khoản khách"; ViewBag.UserFullName = user.Fullname; ViewBag.availableDay = 0; DateTime dt = DateTime.Now.AddDays(-1); if (liciense != null) { if (liciense.PackageId == 1) { ViewBag.licienseType = "Tài khoản thường"; } if (liciense.PackageId == 2) { ViewBag.licienseType = "Tài khoản VIP"; } if (liciense.ExpireDate.CompareTo(DateTime.Now) == -1) { ViewBag.availableDay = 0; } else { ViewBag.availableDay = (liciense.ExpireDate - DateTime.Now).Days; } dt = (DateTime)liciense.ExpireDate; } //ViewBag.ExpireDay = String.Format("{0:dd/ MM/ yyyy}", dt); if (DateTime.Now.CompareTo(dt) <= 0) { ViewBag.ExpireDay = String.Format("{0:dd/ MM/ yyyy}", dt); } else { ViewBag.ExpireDay = "Hết hạn"; } ViewBag.Status = "Đang hoạt động"; if (!user.Active) { ViewBag.Status = "Đã khóa"; } DateTime bt = (DateTime)user.Birthday; ViewBag.BirthDay = String.Format("{0:dd/MM/yyyy}", bt); } catch (Exception e) { throw new Exception(e.Message); } return(View(model)); }