Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "UserId,Username,Password,FullName,MobileNumber,Email,CompanyId,GroupId,UserType,IsBackEnd,FlagActive,UserEntry,DateEntry,UserUpdate,DateUpdate,Department")] rs_user rs_user)
        {
            if (ModelState.IsValid)
            {
                db.rs_user.Add(rs_user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.CompanyId = new SelectList(db.rs_company, "CompanyId", "CompanyCode", rs_user.CompanyId);
            ViewBag.GroupId = new SelectList(db.rs_user_group, "GroupId", "Name", rs_user.GroupId);
            return(View(rs_user));
        }
Ejemplo n.º 2
0
        public ActionResult Create(rs_user rs_user)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    rs_user current = db.rs_user.SingleOrDefault(m => m.Username == rs_user.Username);
                    if (current != null)
                    {
                        TempData["Notification"] = NotificationHelper.Error("Username '" + rs_user.Username + "' already exist.");
                    }
                    else
                    {
                        try
                        {
                            rs_user.Password  = UtilitiesHelper.Encrypt(rs_user.Password);
                            rs_user.IsBackEnd = true;
                            rs_user.UserEntry = User.Identity.Name;
                            rs_user.DateEntry = DateTime.Now;

                            db.rs_user.Add(rs_user);
                            db.SaveChanges();

                            Logger.Log("Add", "New User [Username: "******"]");

                            TempData["Notification"] = NotificationHelper.Inform("New User [Username: "******"]");
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            TempData["Notification"] = NotificationHelper.Error(ex.Message);
                        }
                    }
                }

                //ViewBag.CompanyId = new SelectList(db.rs_company.Where(c => c.FlagActive == true).OrderBy(c => c.Name), "CompanyId", "Name", rs_user.CompanyId);
                ViewBag.GroupId = new SelectList(db.rs_user_group.Where(g => g.FlagActive == true).OrderBy(g => g.Name), "GroupId", "Name", rs_user.GroupId);

                return(View(rs_user));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(rs_action rs_action)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    rs_action current = db.rs_action.Where(m => m.ModuleId == rs_action.ModuleId && m.Name.ToLower() == rs_action.Name.ToLower()).SingleOrDefault();
                    if (current != null)
                    {
                        TempData["Notification"] = NotificationHelper.Error("Action already exist.");
                    }
                    else
                    {
                        try
                        {
                            rs_action.UserEntry = User.Identity.Name;
                            rs_action.DateEntry = DateTime.Now;

                            db.rs_action.Add(rs_action);
                            db.SaveChanges();

                            Logger.Log("Add", "New Action [" + rs_action.Name + "]");

                            TempData["Notification"] = NotificationHelper.Inform("New Action [" + rs_action.Name + "]");
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            TempData["Notification"] = NotificationHelper.Error(ex.Message);
                        }
                    }
                }

                ViewBag.ModuleId = new SelectList(db.rs_module.Where(m => m.FlagActive == true).OrderBy(m => m.Name), "ModuleId", "Name", rs_action.ModuleId);
                //ViewBag.UserEntry = new SelectList(db.rs_user, "UserId", "Username", rs_action.UserEntry);
                //ViewBag.UserUpdate = new SelectList(db.rs_user, "UserId", "Username", rs_action.UserUpdate);
                return(View(rs_action));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(rs_user_group rs_user_group)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    rs_user_group current = db.rs_user_group.Where(s => s.Name == rs_user_group.Name).SingleOrDefault();
                    if (current != null)
                    {
                        TempData["Notification"] = NotificationHelper.Error("User group already exist.");
                    }
                    else
                    {
                        try
                        {
                            rs_user_group.DateEntry = DateTime.Now;
                            rs_user_group.UserEntry = User.Identity.Name;

                            db.rs_user_group.Add(rs_user_group);
                            db.SaveChanges();

                            Logger.Log("Add", "New Group [Name: " + rs_user_group.Name + "]");

                            TempData["Notification"] = NotificationHelper.Inform("New Group [Name: " + rs_user_group.Name + "]");

                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            TempData["Notification"] = NotificationHelper.Error(ex.Message);
                        }
                    }
                }

                return(View(rs_user_group));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Create(LoanFormViewModel model)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    model.LoanForm.RequestorId = AclHelper.GetUserId(User.Identity.Name);
                    model.LoanForm.RequestNo   = 0;
                    model.LoanForm.UpdatedDate = DateTime.Now;
                    model.LoanForm.CreatedDate = DateTime.Now;

                    db.rs_loan_form.Add(model.LoanForm);
                    db.SaveChanges();

                    foreach (string bookId in model.Bookings.BookingIds)
                    {
                        int id;
                        int.TryParse(bookId, out id);
                        rs_bookings booking = db.rs_bookings.Find(id);

                        if (booking != null)
                        {
                            booking.LoanFormId      = model.LoanForm.LoanId;
                            db.Entry(booking).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Ejemplo n.º 6
0
        public void Log(string operation, string description)
        {
            PapayaEntities db = new PapayaEntities();

            rs_syslog syslog = new rs_syslog();

            syslog.Action      = Action;
            syslog.Controller  = Controller;
            syslog.Operation   = operation;
            syslog.Description = description;
            syslog.User        = Username;
            syslog.ClientIP    = ClientIP;
            syslog.LogTime     = DateTime.Now;

            db.rs_syslog.Add(syslog);
            db.SaveChanges();
        }
        public ActionResult Index(ChangePasswordModel cp)
        {
            rs_user rs_user = new rs_user();

            try
            {
                string CurrentPassword = db.rs_user.Where(m => m.Username == User.Identity.Name).Single().Password;
                if (ModelState.IsValid)
                {
                    //if (Crypto.Hash(cp.OldPassword).Remove(32) == CurrentPassword)
                    if (UtilitiesHelper.Encrypt(cp.OldPassword) == CurrentPassword)
                    {
                        rs_user baru = new rs_user();
                        baru = db.rs_user.Where(m => m.Username == User.Identity.Name).Single();

                        //baru.Password = Crypto.Hash(cp.NewPassword).Remove(32);
                        baru.Password = UtilitiesHelper.Encrypt(cp.NewPassword);


                        db.Entry(baru).State = EntityState.Modified;
                        db.SaveChanges();

                        Logger.Log("Change Password", "User Change Password [" + baru.Username + "]");

                        TempData["Notification"] = NotificationHelper.Inform("You have successfully changed your password.");
                    }
                    else
                    {
                        TempData["Notification"] = NotificationHelper.Error("Incorrect old password!");
                    }
                }
            }
            catch (Exception)
            {
                TempData["Notification"] = NotificationHelper.Error("Change password failed!");
            }

            return(View(cp));
        }
Ejemplo n.º 8
0
        public ActionResult Create(SystemModel model, HttpPostedFileBase file)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    model.Step = 2;

                    model.System.CreatedDate  = DateTime.Now;
                    model.System.UpdatedDate  = DateTime.Now;
                    model.System.CurrentLocId = model.CurrentLocId;
                    model.System.OriginLocId  = model.OriginLocId;
                    model.System.OwnedBy      = model.OwnerId;
                    model.System.DivId        = model.DivId;
                    model.System.OwnerShipId  = model.OwnerShipId;
                    model.System.Availability = model.Availability;
                    ViewBag.Availability      = new SelectList(db.rs_assetstatus, "StatusId", "Status");

                    string ownerShip = db.rs_ownership.Find(model.OwnerShipId).OwnerType;
                    int    divNo     = db.rs_division.Find(model.DivId).DivisionNo;

                    model.System.TrackingNo = AssetHelper.GenerateTrackingNo(ownerShip,
                                                                             divNo, model.System.IsSystem, model.System.PurchaseDate);

                    if (AssetHelper.IsImage(file))
                    {
                        file.SaveAs(HttpContext.Server.MapPath("~/AssetsImg/")
                                    + file.FileName);
                        model.System.ImageLink = file.FileName;
                    }

                    db.rs_assets.Add(model.System);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.OriginLocId  = new SelectList(db.rs_locations, "LocationId", "LocationName", model.System.OriginLocId);
                ViewBag.CurrentLocId = new SelectList(db.rs_locations, "LocationId", "LocationName", model.System.CurrentLocId);
                ViewBag.OwnerId      = new SelectList(db.rs_user, "UserId", "Username");
                ViewBag.DivId        = new SelectList(db.rs_division, "DivId", "DivisionNo");
                ViewBag.OwnerShipId  = new SelectList(db.rs_ownership, "OwnerShipId", "OwnerType");
                ViewBag.Availability = new SelectList(db.rs_assetstatus, "StatusId", "Status");

                return(View("Assets", model));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }