public string Binding(string user_types)
        {
            GridRequestParameters param = GridRequestParameters.Current;

            Context.User     user      = RepoUser.FindByPK(UserPrincipal.id);
            List <SolarInap> ListModel = new List <SolarInap>();

            List <Context.SolarInap> items = RepoSolarInap.FindAll(user_types);

            foreach (Context.SolarInap item in items)
            {
                if (item.SalesOrderKontrakListSOId.HasValue)
                {
                    var soKontrak = item.SO.SalesOrderKontrak.SalesOrderKontrakListSo.Where(d => d.Id == item.SalesOrderKontrakListSOId).FirstOrDefault();
                    ListModel.Add(new SolarInap(item, soKontrak));
                }
                else
                {
                    ListModel.Add(new SolarInap(item));
                }
            }
            int total = RepoSolarInap.CountTrans(user_types, param.Filters);

            return(new JavaScriptSerializer().Serialize(new { total = total, data = ListModel }));
        }
Example #2
0
        public ActionResult ChangePassword(User model)
        {
            Context.User dbitem = RepoUser.FindByPK(model.Id);
            dbitem.Password = Encrypt(model.Password);
            RepoUser.save(dbitem, UserPrincipal.id);

            return(RedirectToAction("Index"));
        }
Example #3
0
        public ActionResult EditAkses(int id)
        {
            Context.User dbitem = RepoUser.FindByPK(id);
            User         model  = new User(dbitem);

            ViewBag.name = model.Username;
            return(View("FormAkses", model));
        }
Example #4
0
 public MyPrincipalSerializeModel(Context.User dbitem)
 {
     id        = dbitem.Id;
     username  = dbitem.Username;
     password  = dbitem.Password;
     firstname = dbitem.Fristname;
     lastname  = dbitem.Lastname;
     path_foto = dbitem.path_foto;
 }
 // User Mapping
 public static Library.User Map(Context.User user) => new Library.User
 {
     Id              = user.Id,
     FirstName       = user.FirstName,
     LastName        = user.LastName,
     DefaultLocation = user.DefaultLocation,
     LatestLocation  = user.LatestLocation,
     LatestOrderId   = user.LatestOrderId
 };
Example #6
0
 private void setRole(User model, Context.User dbitem)
 {
     foreach (Context.UserRole d in dbitem.UserRole)
     {
         Role UserRole = model.ListRole.Find(ur => ur.id == d.IdRole);
         if (UserRole != null)
         {
             UserRole.isselect = true;
         }
     }
 }
Example #7
0
        public ActionResult ChangePassword(int id)
        {
            Context.User dbitem = RepoUser.FindByPK(id);
            User         model  = new User(dbitem);

            ViewBag.name = model.Username;
            initRole(model);
            setRole(model, dbitem);
            model.Password = Decrypt(model.Password);
            return(View("ChangePassword", model));
        }
Example #8
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.User dbItem = RepoUser.FindByPK(id);
            dbItem.UserRole.Clear();
            dbItem.UserMenus.Clear();
            RepoUser.delete(dbItem, UserPrincipal.id);

            return(Json(response));
        }
Example #9
0
        public async Task <ActionResult> Add(User model)
        {
            if (ModelState.IsValid)
            {
                //more validation
                bool IsExist = RepoUser.IsExist(model.Username);

                if (IsExist)
                {
                    ModelState.AddModelError("Nik", "Nik & Username sudah terdaftar.");
                    ModelState.AddModelError("Username", "Nik & Username sudah terdaftar");
                    initRole(model);
                    return(View("Form", model));
                }

                if (!model.ListRole.Any(d => d.isselect.Equals(true)))
                {
                    ModelState.AddModelError("roles", "Pilih salah satu atau lebih.");
                    initRole(model);
                    return(View("Form", model));
                }

                Context.User dbitem = new Context.User();
                model.setDb(dbitem);
                dbitem.Password = Encrypt(model.Password);
                //tambahan default menu user
                foreach (var item in RepoMenu.FindAll())
                {
                    dbitem.UserMenus.Add(new Context.UserMenus()
                    {
                        IdMenu = item.Id
                    });
                }
                RepoUser.save(dbitem, UserPrincipal.id);
                string BodyEmail = string.Format("<BR/><BR/>Thank you for your registration," +
                                                 "<p>You already have an account with TMS. You can access  TMS any time by visiting:</p>" +
                                                 "<a href='" + Url.Action("Index", "User", new object { }, Request.Url.Scheme) + "'> TMS MKA</a>" +
                                                 "<p> Username : "******"</p>" +
                                                 "<p> Password : "******"</p>" +
                                                 "<BR/><BR/><BR/> Regards,<BR/><BR/> TMS MKA Team");

                EmailHelper.SendEmail(model.Email, "Email Registration TMS MKA", BodyEmail);

                return(RedirectToAction("EditAkses", "User", new { @id = dbitem.Id }));
            }
            initRole(model);
            return(View("Form", model));
        }
Example #10
0
        public ActionResult Edit(User model)
        {
            if (ModelState.IsValid)
            {
                Context.User dbitem = RepoUser.FindByPK(model.Id);
                dbitem.UserRole.Clear();
                model.setDb(dbitem);
                List <int?> idMenus = dbitem.UserMenus.Select(i => i.IdMenu).ToList();
                string      query   = "DELETE FROM dbo.\"UserRole\" WHERE \"IdUser\" = " + model.Id + ";";
                foreach (var item in RepoMenu.FindAll().Where(d => !idMenus.Contains(d.Id)))
                {
                    dbitem.UserMenus.Add(new Context.UserMenus()
                    {
                        IdMenu = item.Id
                    });
                    query += "INSERT INTO dbo.\"UserMenus\" (\"IdUser\", \"IdMenu\") VALUES ( " + model.Id + ", " + item.Id + ");";
                }
                RepoUser.save(dbitem, UserPrincipal.id, query);

                //send email
                //System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
                //    new System.Net.Mail.MailAddress("tms.kamanggala.net", "TMS MKA Registration"),
                //    new System.Net.Mail.MailAddress("*****@*****.**")
                //);
                //System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**");
                //m.Subject = "Email Registration TMS MKA " + dbitem.Password;
                //m.Body = "";
                //m.IsBodyHtml = true;
                //SmtpClient smtp = new SmtpClient("kamanggala.com", 110);
                //var credential = new NetworkCredential
                //{
                //    UserName = "******",
                //    Domain = "kamanggala.com"
                //};
                //smtp.EnableSsl = false;
                //smtp.Credentials = credential;
                ////smtp.UseDefaultCredentials = false;
                ////smtp.Credentials = new NetworkCredential("tms.kamanggala.net", "", "kamanggala.com");
                ////smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                ////ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                ////await smtp.SendMailAsync(m);
                //smtp.Send(m);

                return(RedirectToAction("Index"));
            }
            initRole(model);
            return(View("Form", model));
        }
Example #11
0
        public ActionResult EditAkses(User model)
        {
            UserMenu[] result = JsonConvert.DeserializeObject <UserMenu[]>(model.StrMenu);
            model.ListMenu = result.ToList();
            Context.User dbitem = RepoUser.FindByPK(model.Id);
            dbitem.UserMenus.Clear();
            var query = "DELETE FROM dbo.\"UserMenus\" WHERE \"IdUser\" = " + dbitem.Id + ";";

            foreach (var item in model.ListMenu)
            {
                dbitem.UserMenus.Add(item.setDb(new Context.UserMenus()));
                query += "INSERT INTO dbo.\"UserMenus\" (\"IdUser\", \"IdMenu\", \"IsCreate\", \"IsRead\", \"IsUpdate\", \"IsDelete\", \"IsPrint\", \"IsProses\") VALUES (" + model.Id + ", " + item.IdMenu +
                         ", " + item.IsCreate + ", " + item.IsRead + ", " + item.IsUpdate + ", " + item.IsDelete + ", " + item.IsPrint + ", " + item.IsProses + ");";
            }
            RepoUser.save(dbitem, UserPrincipal.id, query);
            return(RedirectToAction("Index"));
        }
Example #12
0
        public string BindingByUser(string modul, int user_id)
        {
            Context.User    usr       = RepoUser.FindByPK(user_id);
            List <UserMenu> ListModel = new List <UserMenu>();

            foreach (var item in usr.UserMenus.Where(m => m.Menu.Modul == modul))
            {
                ListModel.Add(new UserMenu(item));
            }

            List <Context.Menu> items = RepoMenu.FindAll().Where(d => d.Modul == modul && !usr.UserMenus.Select(f => f.IdMenu).Contains(d.Id)).ToList();

            foreach (Context.Menu item in items)
            {
                ListModel.Add(new UserMenu(item));
            }
            return(new JavaScriptSerializer().Serialize(new { total = ListModel.Count(), data = ListModel }));
        }
Example #13
0
        public string this[string idUserAlert]
        {
            get
            {
                string[] idUsers = Regex.Split(idUserAlert, ",");

                foreach (string idUser in idUsers)
                {
                    id = Convert.ToInt32(idUser);

                    Context.User dbitem = context.User.Where(d => d.Id == id).FirstOrDefault();
                    User         model  = new User(dbitem);
                    userAlert += model.Username + ",";
                }

                userAlert = userAlert.Trim(',');

                return(userAlert);
            }
        }
Example #14
0
        public ActionResult Login(User model, string returnUrl = "")
        {
            Context.User _user = RepoUser.FindByUsername(model.Username);

            if (_user != null)
            {
                if (Decrypt(_user.Password) != model.Password)
                {
                    ModelState.AddModelError("Password", "Password tidak cocok.");
                    return(View(model));
                }

                //login succes
                //Models.User serializeModel = new Models.User(_user);
                MyPrincipalSerializeModel serializeModel = new MyPrincipalSerializeModel(_user);

                string userData = JsonConvert.SerializeObject(serializeModel);
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
                                                                                     serializeModel.username,
                                                                                     DateTime.Now,
                                                                                     DateTime.Now.AddMinutes(120),
                                                                                     true,
                                                                                     userData,
                                                                                     FormsAuthentication.FormsCookiePath);

                string     encTicket = FormsAuthentication.Encrypt(authTicket);
                HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                Response.Cookies.Add(faCookie);

                return(RedirectToAction("Index", "Home"));
                //RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("Username", "Username tidak terdaftar.");
                return(View(model));
            }
        }
Example #15
0
        public void setDb(Context.User dbitem)
        {
            dbitem.Id        = Id;
            dbitem.Nik       = Nik;
            dbitem.Username  = Username;
            dbitem.Fristname = Fristname;
            dbitem.Lastname  = Lastname;
            dbitem.Email     = Email;
            dbitem.Phone     = Phone;
            dbitem.path_foto = path_foto;
            if (Password != null && Password != "")
            {
                using (MD5 md5Hash = MD5.Create())
                {
//                dbitem.Password = AppHelper.GetMd5Hash(md5Hash, Password);
                }
            }

            //foreach (Role item in ListRole.Where(d => d.isselect == true))
            //{
            //    dbitem.UserRole.Add(new UserRole() { IdRole = item.id });
            //}
        }
Example #16
0
        public User(Context.User dbitem)
        {
            Id        = dbitem.Id;
            Nik       = dbitem.Nik;
            Username  = dbitem.Username;
            Fristname = dbitem.Fristname;
            Lastname  = dbitem.Lastname;
            Email     = dbitem.Email;
            Phone     = dbitem.Phone;
            Password  = dbitem.Password;
            path_foto = dbitem.path_foto;
            //ListRole = new List<Role>();
            //foreach (var item in dbitem.UserRole)
            //{
            //    ListRole.Add(new Role(item.Role));
            //}

            ListMenu = new List <UserMenu>();
            foreach (var item in dbitem.UserMenus)
            {
                ListMenu.Add(new UserMenu(item));
            }
        }