Exemple #1
0
        public IHttpActionResult ResourceList()
        {
            var entities = new EmployeeEntities3();
            var records  = entities.Laptop_List.ToList();

            return(Ok(records));
        }
        public ActionResult Login(UserDetail u)
        {
            if (ModelState.IsValid) // this is check validity
            {
                using (EmployeeEntities3 dc = new EmployeeEntities3())
                {
                    var v = dc.UserDetails.Where(a => a.UserName.Equals(u.UserName) && a.Password.Equals(u.Password)).FirstOrDefault();
                    if (v == null)
                    {
                        ViewBag.Error = "Invalid User Credentials";
                    }
                    if (v != null)
                    {
                        TempData["UserName"] = v.FirstName + ' ' + v.LastName;
                        TempData["LoginId"]  = v.LoginId;

                        if (v.IsDeleted == true)
                        {
                            ViewBag.Message = "Invalid User";
                        }
                        else
                        {
                            Session["LogedUserID"] = v.LoginId.ToString();
                            return(RedirectToAction("AfterLogin"));
                        }

                        return(RedirectToAction("Register"));
                    }
                }
            }
            return(View(u));
        }
        public IHttpActionResult Resourcelist()
        {
            var entities = new EmployeeEntities3();
            var rec      = entities.Mobile_List.ToList();

            return(Ok(rec));
        }
 public ActionResult AfterDelete(int LoginId)
 {
     using (EmployeeEntities3 dc = new EmployeeEntities3())
     {
         UserDetail u = dc.UserDetails.Find(LoginId);
         u.IsDeleted = true;
         u.IsActive  = false;
         //dc.UserDetails.Remove(u);
         dc.SaveChanges();
         return(RedirectToAction("AfterDelete"));
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="LoginId"></param>
 /// <returns></returns>
 public ActionResult Edit(int LoginId)
 {
     using (EmployeeEntities3 dc = new EmployeeEntities3())
     {
         UserDetail u = dc.UserDetails.Find(LoginId);
         if (u == null)
         {
             return(HttpNotFound());
         }
         return(View(u));
     }
 }
        public ActionResult Delete(int LoginId)
        {
            using (EmployeeEntities3 dc = new EmployeeEntities3())
            {
                UserDetail u = dc.UserDetails.Find(LoginId);
                if (u == null)
                {
                    ViewBag.Message = "No Records Found";
                }

                return(View(u));
            }
        }
 public ActionResult Edit(UserDetail u)
 {
     using (EmployeeEntities3 dc = new EmployeeEntities3())
     {
         if (ModelState.IsValid)
         {
             dc.Entry(u).State = EntityState.Modified;
             dc.SaveChanges();
             return(RedirectToAction("AfterEdit"));
         }
         return(View());
     }
 }
        public IHttpActionResult Login(LoginDetail userInfo)
        {
            if (ModelState.IsValid)
            {
                using (EmployeeEntities3 entity = new EmployeeEntities3())
                {
                    var record = entity.LoginDetails.Where(x => x.UserName.Equals(userInfo.UserName) && x.Password.Equals(userInfo.Password)).FirstOrDefault();
                    if (record != null)
                    {
                        return(Ok(true));
                    }
                }
            }

            return(Ok(false));
        }
        public ActionResult Retrieve(String search)
        {
            using (EmployeeEntities3 dc = new EmployeeEntities3())
            {
                //  if (SearchBy == UserName)
                //{
                List <UserDetailViewModel> userDetailsList = new List <UserDetailViewModel>();

                //userDetailsList = (from u in dc.UserDetails
                //                   where u.FirstName.Contains(search)
                //                   select u).ToList();

                var list = dc.UserDetails
                           .Join(dc.RoleMasters,
                                 c => c.RoleId,
                                 o => o.RoleId,
                                 (c, o) => new UserDetailViewModel()
                {
                    LoginId   = c.LoginId,
                    FirstName = c.FirstName,
                    LastName  = c.LastName,
                    UserName  = c.UserName,
                    Password  = c.Password,
                    Contact   = c.Contact,

                    RoleName = o.RoleName
                }).ToList();

                userDetailsList = list;


                if (userDetailsList != null && userDetailsList.Count() > 0 && !string.IsNullOrEmpty(search))
                {
                    return(View(userDetailsList.Where(x => x.FirstName.ToLower().Contains(search) || search == null).ToList()));
                }
                else
                {
                    return(View("Retrieve", userDetailsList));
                }
            }
        }
        public IHttpActionResult CheckAvailability(HistoryDetail userInfo)
        {

            if (ModelState.IsValid)
            {
                using (EmployeeEntities3 entity = new EmployeeEntities3())
                {

                    foreach (var book in entity.HistoryDetails)
                    {
                        if (userInfo.Resource_Id == book.Resource_Id)
                        {
                            if (userInfo.Start_Date > book.End_Date)
                            {
                                return Ok(true);
                            }
                            if (userInfo.Start_Date <= book.End_Date)
                            {
                                return Ok(false);
                            }
                        }
                        if (userInfo.Resource_Id != book.Resource_Id)
                        {
                            return Ok(true);
                        }
                    }

                    //var record=entity.HistoryDetails.Where(x => x.Resource_Id == (userInfo.Resource_Id) && x.Start_Date > (userInfo.End_Date));
                    //entity.HistoryDetails.Where(x => x.Resource_Id.Equals(userInfo.Resource_Id) && x.Start_Date > (userInfo.End_Date));
                    //var record = entity.HistoryDetails.Where(x => x.Start_Date>=(userInfo.Start_Date) && x.End_Date.Equals(userInfo.End_Date)).FirstOrDefault();
                    //if (record != null)
                    //{
                    //    return Ok(false);
                    //}

                }
            }
           return Ok(false);
        }
        public ActionResult Register(UserDetail u)
        {
            if (ModelState.IsValid)
            {
                using (EmployeeEntities3 dc = new EmployeeEntities3())
                {
                    dc.UserDetails.Add(u);
                    //you should check duplicate registration here
                    if (TempData.ContainsKey("LoginId"))
                    {
                        u.CreatedBy = Convert.ToString(TempData.Peek("LoginId"));
                    }
                    //u.CreatedOn = Convert.ToString( DateTime.Now);



                    dc.SaveChanges();
                    ModelState.Clear();
                    u = null;
                    return(RedirectToAction("AfterRegister"));
                }
            }
            return(View(u));
        }
 public IHttpActionResult Availability()
 {
     var entities = new EmployeeEntities3();
     var rec = entities.HistoryDetails.ToList();
     return Ok(rec);
 }