Esempio n. 1
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                UserViewModel model = null;

                using (Domain.ZanyContext context = new Domain.ZanyContext())
                {
                    var sourceObj = context.Users
                                        .Where(u => u.UserId == id)
                                        .FirstOrDefault();

                    if (sourceObj != null)
                    {
                        context.Users.Remove(sourceObj);
                        context.SaveChanges();
                    }
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 2
0
        public ActionResult Create(UserViewModel model)
        {
            try
            {
                using (Domain.ZanyContext context = new Domain.ZanyContext())
                {
                    var newEntity = context.Users.Create();

                    newEntity.Email = model.Email;
                    newEntity.FacebookHandle = model.FacebookHandle;
                    newEntity.FirstName = model.FirstName;
                    newEntity.LastName = model.LastName;
                    newEntity.TwitterHandle = model.TwitterHandle;
                    newEntity.UserName = model.Username;
                    newEntity.WebUrl = model.WebUrl;

                    context.Users.Add(newEntity);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 3
0
        internal static IList<UserViewModel> GetAllUsers()
        {
            IList<UserViewModel> allUsers = new List<UserViewModel>();

            using (Domain.ZanyContext context = new Domain.ZanyContext())
            {
                var sourceList = context.Users;
                foreach (var item in sourceList)
                {
                    allUsers.Add(new UserViewModel(item));
                }
            }

            return allUsers;
        }
Esempio n. 4
0
        public ActionResult Delete(int id)
        {
            UserViewModel model = null;

            using (Domain.ZanyContext context = new Domain.ZanyContext())
            {
                var sourceObj = context.Users
                                    .Where(u => u.UserId == id)
                                    .FirstOrDefault();

                if (sourceObj != null)
                {
                    model = new UserViewModel(sourceObj);
                }
            }

            return View(model);
        }
Esempio n. 5
0
        public ActionResult Index()
        {
            IList<UserViewModel> model = null;

            using (Domain.ZanyContext context = new Domain.ZanyContext())
            {
                model = Helpers.Utilities.ConvertToList(context.Users.ToList());
            }

            return View(model);
        }
Esempio n. 6
0
        public ActionResult Edit(UserViewModel model)
        {
            try
            {
                using (Domain.ZanyContext context = new Domain.ZanyContext())
                {
                    var toUpdate = context.Users
                                        .Where(u => u.UserId == model.UserId)
                                        .FirstOrDefault();

                    if (toUpdate != null)
                    {
                        toUpdate.Email = model.Email;
                        toUpdate.FacebookHandle = model.FacebookHandle;
                        toUpdate.FirstName = model.FirstName;
                        toUpdate.LastName = model.LastName;
                        toUpdate.TwitterHandle = model.TwitterHandle;
                        toUpdate.UserName = model.Username;
                        toUpdate.WebUrl = model.WebUrl;

                        context.SaveChanges();
                    }
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }