Exemple #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));
            }
        }
Exemple #2
0
 public owner_user GetDbObject(owner_user dbItem)
 {
     dbItem.id       = this.Id;
     dbItem.id_owner = this.IdOwner;
     dbItem.username = this.Username;
     return(dbItem);
 }
Exemple #3
0
 public OwnerUserFormStub(owner_user dbItem)
     : this()
 {
     this.Id       = dbItem.id;
     this.IdOwner  = dbItem.id_owner;
     this.Username = dbItem.username;
 }
Exemple #4
0
        public JsonResult DeleteUser(Guid id)
        {
            ResponseModel response = new ResponseModel(true);
            owner_user    dbItem   = RepoOwner.FindByPkUser(id);

            RepoOwner.DeleteUser(dbItem);

            return(Json(response));
        }
Exemple #5
0
 public owner_user SaveUser(owner_user dbItem)
 {
     if (dbItem.id == Guid.Empty) //create
     {
         dbItem.id = Guid.NewGuid();
         owner_user checkUnique = context.owner_user.Where(x => x.id == dbItem.id).FirstOrDefault();
         while (checkUnique != null)
         {
             dbItem.id   = Guid.NewGuid();
             checkUnique = context.owner_user.Where(x => x.id == dbItem.id).FirstOrDefault();
         }
         context.owner_user.Add(dbItem);
     }
     else //edit
     {
         var entry = context.Entry(dbItem);
         entry.State = EntityState.Modified;
     }
     context.SaveChanges();
     return(dbItem);
 }
Exemple #6
0
 public void DeleteUser(owner_user dbItem)
 {
     context.owner_user.Remove(dbItem);
     context.SaveChanges();
 }
Exemple #7
0
 public OwnerPresentationStub(owner_user dbItem)
 {
     this.Id       = dbItem.id;
     this.IdOwner  = dbItem.id_owner;
     this.Username = dbItem.username;
 }