Пример #1
0
        public ActionResult AssignUser(OwnerUserFormStub model)
        {
            //bool isNameExist = RepoOwner.Find().Where(p => p.name == model.Name).Count() > 0;

            if (ModelState.IsValid)
            {
                var checkUniqueness = RepoOwner.CheckUsername(model.Username, model.IdOwner);
                if (checkUniqueness == false)
                {
                    ModelState.AddModelError("Username", "Username sudah pernah di assign pada perusahaan ini sebelumnya");
                    return(View("FormAssign", model));
                }

                owner_user dbItem = new owner_user();
                dbItem = model.GetDbObject(dbItem);

                owner_user savedData = RepoOwner.SaveUser(dbItem);

                owner ownerData = RepoOwner.FindOwnerByUserName(savedData.username);

                //message
                //string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString();
                this.SetMessage(savedData.username + " berhasil di assign ke " + ownerData.name);

                return(RedirectToAction("Index"));
            }
            else
            {
                //var errors = ModelState.Select(x => x.Value.Errors)
                //           .Where(y => y.Count > 0)
                //           .ToList();
                return(View("FormAssign", model));
            }
        }