public ActionResult Edit(int?id, LearningMVC.Models.User userDetails)
        {
            TempData["TempData Name"] = "Akhil";

            try
            {
                var dbContext = new MyDBDataContext();
                var user      = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                if (user != null)
                {
                    user.FirstName   = userDetails.FirstName;
                    user.LastName    = userDetails.LastName;
                    user.Address     = userDetails.Address;
                    user.PhoneNo     = userDetails.PhoneNo;
                    user.EMail       = userDetails.EMail;
                    user.Company     = userDetails.Company;
                    user.Designation = userDetails.Designation;
                    dbContext.SubmitChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        /// <summary>
        /// Get Action for Details
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int?id)
        {
            var dbContext = new MyDBDataContext();

            Mapper.CreateMap <LearningMVC.User, LearningMVC.Models.User>();
            var userDetails = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);

            LearningMVC.Models.User user = Mapper.Map <LearningMVC.User, LearningMVC.Models.User>(userDetails);
            return(View(user));
        }
 public ActionResult Create(LearningMVC.Models.User userDetails)
 {
     try
     {
         Mapper.CreateMap <LearningMVC.Models.User, LearningMVC.User>();
         var dbContext = new MyDBDataContext();
         var user      = Mapper.Map <LearningMVC.Models.User, LearningMVC.User>(userDetails);
         dbContext.Users.InsertOnSubmit(user);
         dbContext.SubmitChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        /// <summary>
        /// Get Action for index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            Mapper.CreateMap <LearningMVC.User, LearningMVC.Models.User>();
            var dbContext = new MyDBDataContext();
            var userList  = from user in dbContext.Users select user;
            var users     = new List <LearningMVC.Models.User>();

            if (userList.Any())
            {
                foreach (var user in userList)
                {
                    LearningMVC.Models.User userModel = Mapper.Map <LearningMVC.User, LearningMVC.Models.User>(user);
                    users.Add(userModel);
                }
            }

            return(View(users));
        }
        public ActionResult Delete(int?id, LearningMVC.Models.User userDetails)
        {
            try
            {
                var dbContext = new MyDBDataContext();
                var user      = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                if (user != null)
                {
                    dbContext.Users.DeleteOnSubmit(user);
                    dbContext.SubmitChanges();
                }

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