public ActionResult Create([Bind(Include = "ID,DEPT_NAME,DEPT_ID,IsActive")] departmant departmantModel)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }

            //departmant dbDept = new departmant();
            try {
                if (db.departmant.Any(x => x.DEPT_ID == departmantModel.DEPT_ID))
                {
                    TempData["info"] = departmantModel.DEPT_ID + " " + "Department already created!";
                    return(RedirectToAction("Create", "Departmants"));
                }
                if (ModelState.IsValid)
                {
                    db.departmant.Add(departmantModel);
                    db.SaveChanges();
                    TempData["info"] = "Department Created Succesfull";
                    return(RedirectToAction("Index", "Location"));
                }
            }
            catch (Exception ex)
            {
                TempData["info"] = "Problem Occured: " + " " + ex.Message;
                return(RedirectToAction("Index", "Location"));
            }


            return(View(departmantModel));
        }
Exemple #2
0
        public ActionResult Add(UserVM model, int?LocationID)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(RedirectToAction("Index", "Home"));
            }
            SetRoleList();
            ViewBag.DepartmentList = new SelectList(GetDepartmentList(), "ID", "DEPT_NAME");
            try
            {
                // if Model does not have any validation error
                if (model != null)
                {
                    // Set role List to dropdown list.
                    var userexist = _userRepository.UserFind(model.UNI_ID);
                    if (userexist != null)
                    {
                        return(Json(new ResultJson {
                            Success = false, Message = userexist.UNI_ID + " User Already Registered!"
                        }));
                    }
                    if (string.Compare(model.PASSWORD.Trim().ToUpper(), model.ComparePassword.Trim().ToUpper()) != 0)
                    {
                        return(Json(new ResultJson {
                            Success = false, Message = " Password should match with compare password field!"
                        }));
                    }
                    // Fill as user view model user object from the reguested model and match the value to configure them.
                    user Userdb = new user();
                    Userdb.UNI_ID          = model.UNI_ID.Trim().ToUpper();
                    Userdb.FIRST_NAME      = model.FIRST_NAME;
                    Userdb.LAST_NAME       = model.LAST_NAME.ToUpper();
                    Userdb.EMAIL           = model.EMAIL;
                    Userdb.FK_LOCATION_ID  = LocationID;
                    Userdb.FK_PRIVILEGE_ID = model.FK_PRIVILEGE_ID;
                    Userdb.IsActive        = model.IsActive;
                    Userdb.PHONE           = model.PHONE;
                    Userdb.PASSWORD        = CustomEncrypt.passwordEncrypt(model.PASSWORD.Trim(), EncryptionKey);
                    Userdb.CREATED_DATE    = DateTime.Now;
                    Userdb.UPDATED_DATE    = DateTime.Now;
                    Userdb.TITLE           = model.TITLE;
                    db.user.Add(Userdb);
                    db.SaveChanges();
                    return(Json(new ResultJson {
                        Success = true, Message = "User Added Successfully"
                    }));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                return(Json(new ResultJson {
                    Success = false, Message = "Error Occured while adding User!"
                }));
            }
        }
Exemple #3
0
        public ActionResult Login(LoginViewModel model, string ReturnUrl = "")
        {
            string EncryptionKey = "SHA512";
            string message       = "";

            if (ModelState.IsValid)
            {
                using (EastMedDB db = new EastMedDB())
                {
                    var userexist = db.user.Where(a => a.UNI_ID == model.UNI_ID && a.IsActive == true).FirstOrDefault();
                    if (userexist != null)
                    {
                        if (string.Compare((model.Password.Trim()), CustomDecrypt.passwordDecrypt(userexist.PASSWORD, EncryptionKey)) == 0)
                        {
                            // In here 2 method has been used to save user login atraction to specific pages
                            // Sessions and cookies give as to control menus and specification for each user.
                            // Cookies to used authorized the application and protect to anonymous enter
                            // Cookies are encrypted in client site the avoid from the cookie attacks.

                            Session["RoleID"]         = userexist.FK_PRIVILEGE_ID;
                            Session["UserName"]       = userexist.FIRST_NAME + " " + userexist.LAST_NAME;
                            Session["UserID"]         = userexist.UNI_ID;
                            Session["UserDatabaseID"] = userexist.ID;
                            int    timeout   = model.RememberMe ? 525600 : 30; // 30 min to expire the cookie.
                            var    ticket    = new FormsAuthenticationTicket(model.UNI_ID, model.RememberMe, timeout);
                            string encrypted = FormsAuthentication.Encrypt(ticket);
                            var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                            cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                            cookie.HttpOnly = true;
                            Response.Cookies.Add(cookie);
                            if (Url.IsLocalUrl(ReturnUrl))
                            {
                                return(Redirect(ReturnUrl));
                            }
                            else
                            {
                                userexist.LAST_LOGINDATE = DateTime.Now;
                                db.user.Attach(userexist);
                                var entry = db.Entry(userexist);
                                entry.Property(x => x.LAST_LOGINDATE).IsModified = true;
                                db.SaveChanges();
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Invalid user/pass");
                            return(View());
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid user/pass");
                        return(View());
                    }
                }
            }
            ViewBag.Message = message;
            return(View());
        }
        // GET: Complaint/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            complaint complaint      = db.complaint.Find(id);
            var       queryComplaint = (from comp in db.complaint
                                        join u in db.user on comp.FK_USER_ID equals u.ID
                                        join cate in db.category on comp.FK_CATEGORY_ID equals cate.ID
                                        join loc in db.location on comp.FK_Location_ID equals loc.ID
                                        join i in db.item on comp.FK_ITEM_ID equals i.ID
                                        join it in db.itemtype on i.ID equals it.ID
                                        orderby(cate.CATEGORY_NAME)
                                        where comp.ID == id
                                        select new ComplaintModel
            {
                STATUS = comp.STATUS,
                COMMENT = comp.COMMENT,
                UserName = u.FIRST_NAME + " " + u.LAST_NAME,
                ITEM_ID = comp.ITEM_ID,
                IsActive = comp.IsActive,
                ComplaintId = comp.ID,
                CategoryName = cate.CATEGORY_NAME,
                PRIORITY = comp.PRIORITY,
                STARTDATE = comp.START_DATE,
                itemName = i.ITEM_NAME,
                RoomNo = loc.ROOM_ID,
                ImgUrl = comp.ImgURL
            });

            if (queryComplaint == null)
            {
                return(HttpNotFound());
            }
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (complaint.STATUS.Trim().ToUpper() == "NEW" & SessionControl == 7)
            {
                complaint.STATUS = "SEEN".Trim().ToUpper();
                db.complaint.Attach(complaint);
                var entry = db.Entry(complaint);
                entry.Property(x => x.STATUS).IsModified = true;
                db.SaveChanges();
            }
            return(View(complaint)); //Instead of using single return value it is faster and reliable to use it "singleordefault".
        }
Exemple #5
0
 public ActionResult Create([Bind(Include = "ID,CATEGORY_NAME,DESCRIPTION,FK_USER_ID,IsActive")] category category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.category.Add(category);
             db.SaveChanges();
             TempData["info"] = "Adding category Succesful";
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         TempData["error"] = ex.Message;
     }
     ViewBag.FK_USER_ID = new SelectList(db.user.Where(x => x.IsActive == true && x.FK_PRIVILEGE_ID == 7), "ID", "FIRST_NAME", "LAST_NAME", category.FK_USER_ID);
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "ID,COMMENT,STATUS,START_DATE,PRIORITY,FK_USER_ID,FK_CATEGORY_ID,IsActive,FK_Location_ID,FK_ITEM_ID,ITEM_ID")] complaint complaint)
 {
     if (ModelState.IsValid)
     {
         db.complaint.Attach(complaint);
         var entry = db.Entry(complaint);
         entry.Property(x => x.COMMENT).IsModified        = true;
         entry.Property(x => x.START_DATE).IsModified     = true;
         entry.Property(x => x.PRIORITY).IsModified       = true;
         entry.Property(x => x.FK_USER_ID).IsModified     = true;
         entry.Property(x => x.IsActive).IsModified       = true;
         entry.Property(x => x.FK_Location_ID).IsModified = true;
         entry.Property(x => x.FK_ITEM_ID).IsModified     = true;
         entry.Property(x => x.ITEM_ID).IsModified        = true;
         db.Entry(complaint).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     SetCategory();
     //ViewBag.Itemlist = new SelectList(GetItemType(), "ID", "Item_Type");
     ViewBag.DepartmentList = new SelectList(GetDepartmentList(), "ID", "DEPT_NAME");
     return(View(complaint));
 }
        public ActionResult Create([Bind(Include = "ID,ROOM_ID,TYPE,FK_DEPT_ID,CREATED_DATE,UPDATED_DATE,IsActive")] location location)
        {
            var SessionControl = Convert.ToInt32(HttpContext.Session["RoleID"]);

            if (SessionControl != 5)
            {
                return(HttpNotFound());
            }
            try
            {
                if (db.location.Any(x => x.ROOM_ID.Trim().ToUpper() == location.ROOM_ID.Trim().ToUpper()))
                {
                    TempData["info"] = location.ROOM_ID + " " + " Location already created!";
                    return(RedirectToAction("Create", "Location"));
                }
                if (ModelState.IsValid)
                {
                    location.ROOM_ID      = location.ROOM_ID.Trim().ToUpper();
                    location.TYPE         = location.TYPE.Trim().ToLower();
                    location.CREATED_DATE = DateTime.Now;
                    location.UPDATED_DATE = DateTime.Now;
                    db.location.Add(location);
                    db.SaveChanges();
                    TempData["Msg"] = location.ROOM_ID + " " + "Location has been saved succeessfully";

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException ex) // or use DataException
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                TempData["info"] = "Error Occured : " + " " + ex.Message;
                return(RedirectToAction("Create", "Location"));
            }

            ViewBag.FK_DEPT_ID = new SelectList(db.departmant, "ID", "DEPT_NAME", location.FK_DEPT_ID);

            return(View(location));
        }
        public ActionResult Edit(UserVM User, int?id)
        {
            try
            {
                ViewBag.Role = db.user.Where(x => x.ID == id).Include(x => x.privilege).SingleOrDefault().privilege.ROLE;

                if (ModelState.IsValid)
                {
                    var dbUser = db.user.Where(x => x.ID == id).SingleOrDefault();
                    dbUser.UPDATED_DATE = DateTime.Now;
                    dbUser.PASSWORD     = CustomEncrypt.passwordEncrypt(User.PASSWORD, EncryptionKey);
                    dbUser.PHONE        = User.PHONE;
                    dbUser.EMAIL        = User.EMAIL;
                    db.user.Attach(dbUser);
                    var entry = db.Entry(dbUser);
                    entry.Property(x => x.UPDATED_DATE).IsModified = true;
                    entry.Property(x => x.PASSWORD).IsModified     = true;
                    entry.Property(x => x.PHONE).IsModified        = true;
                    entry.Property(x => x.EMAIL).IsModified        = true;
                    db.SaveChanges();
                    TempData["info"] = "Profile Edit Succesfully";

                    return(Json(new ResultJson {
                        Success = false, Message = "Edit User Succesfull!"
                    }));
                }
                else
                {
                    //ModelState.AddModelError()
                    return(Json(new ResultJson {
                        Success = false, Message = "User Does not find!"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultJson {
                    Success = false, Message = "Error Occured while Editing User!"
                }));
            }
        }
 public void Save()
 {
     _context.SaveChanges();
 }
Exemple #10
0
        public ActionResult Create(ComplaintHistoryModel model, int?id)
        {
            // complaint status
            string            statusc        = "";
            int               sessionControl = Convert.ToInt32(HttpContext.Session["UserDatabaseID"]);
            complaint_history comphist       = new complaint_history();

            int       quote     = (int)id;
            complaint complaint = db.complaint.Find(id);

            if (model != null)
            {
                try
                {
                    if (Convert.ToInt32(model.Status) == 0)
                    {
                        comphist.STATUS = statusc = "On Progress".Trim().ToUpper();
                    }
                    if (Convert.ToInt32(model.Status) == 1)
                    {
                        comphist.STATUS = statusc = "SOLVED".Trim().ToUpper();
                    }
                    else if (Convert.ToInt32(model.Status) == 2)
                    {
                        comphist.STATUS = statusc = "UNSOLVED".Trim().ToUpper();
                    }

                    comphist.MODIFIED_TIME      = DateTime.Now;
                    comphist.COMMENT            = model.Comment;
                    comphist.FK_CATEGORYUSER_ID = sessionControl;
                    comphist.FK_COMPLAINT_ID    = quote;
                    comphist.FK_CATEGORY_ID     = model.CategoryID;
                    db.complaint_history.Add(comphist);
                    db.SaveChanges();
                    if (Convert.ToInt32(model.Status) == 0)
                    {
                        complaint.STATUS = statusc = "ON PROGRESS".Trim().ToUpper();
                    }
                    if (Convert.ToInt32(model.Status) == 1)
                    {
                        complaint.STATUS = statusc = "SOLVED".Trim().ToUpper();
                    }
                    else if (Convert.ToInt32(model.Status) == 2)
                    {
                        complaint.STATUS = statusc = "UNSOLVED".Trim().ToUpper();
                    }
                    db.complaint.Attach(complaint);
                    var entry = db.Entry(complaint);
                    entry.Property(x => x.STATUS).IsModified = true;
                    db.SaveChanges();
                    TempData["Info"] = "Complaint " + comphist.ID + " of status successfuly changed to " + comphist.STATUS;
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    TempData["error"] = "Error occured while modifying complaint";
                    return(View(model));
                }
            }
            var types = new List <ComplaintHistoryStatus>();

            types.Add(new ComplaintHistoryStatus()
            {
                Id = 0, ComplaintStatus = "On Progress"
            });
            types.Add(new ComplaintHistoryStatus()
            {
                Id = 1, ComplaintStatus = "Solved"
            });
            types.Add(new ComplaintHistoryStatus()
            {
                Id = 2, ComplaintStatus = "UnSolved"
            });
            ViewBag.PartialTypes   = types;
            ViewBag.FK_CATEGORY_ID = new SelectList(db.category, "ID", "CATEGORY_NAME", complaint.FK_CATEGORY_ID);
            return(View(model));
        }