Exemple #1
0
        public ActionResult Create(UserViewModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(user));
                }
                if (user.ImageUpload != null)
                {
                    var fileName  = Path.GetFileNameWithoutExtension(user.ImageUpload.FileName);
                    var extension = Path.GetExtension(user.ImageUpload.FileName);
                    fileName    = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    user.Avatar = "~/assets/uploadImages/" + fileName;
                    user.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/assets/uploadImages/"), fileName));
                }

                var modelBL = _mapper.Map <UserBL>(user);
                _service.Create(modelBL);

                var users   = _service.GetAll();
                var usersPL = _mapper.Map <IEnumerable <UserViewModel> >(users);

                return(Json(new { success = true, html = RenderRazorViewToHtml.RenderRazorViewToString(this, "ViewAll", usersPL), message = "Submitted Successfully " }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }));
            }
        }
Exemple #2
0
 public ActionResult Delete(int id)
 {
     try
     {
         _service.Delete(id);
         var users   = _service.GetAll();
         var usersPL = _mapper.Map <IEnumerable <UserViewModel> >(users);
         return(Json(new { success = true, html = RenderRazorViewToHtml.RenderRazorViewToString(this, "ViewAll", usersPL), message = "Deleted Successfully " }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }));
     }
 }
Exemple #3
0
        public ActionResult Edit(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var modelBL = _mapper.Map <UserBL>(model);

            _service.Update(modelBL);

            var users   = _service.GetAll();
            var usersPL = _mapper.Map <IEnumerable <UserViewModel> >(users);

            return(Json(new { success = true, html = RenderRazorViewToHtml.RenderRazorViewToString(this, "ViewAll", usersPL), message = "Edited Successfully " }, JsonRequestBehavior.AllowGet));
        }