public ActionResult Create(CustomerModels model) { try { byte[] photoByte = null; if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Create", model)); } if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.ImageURL = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; } var msg = ""; var id = ""; model.CreatedBy = CurrentUser.Email; model.Password = CommonHelper.Encrypt(model.Password); var result = _factory.CreateOrUpdate(model, ref id, ref msg); if (result) { if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null) { var path = Server.MapPath("~/Uploads/Employees/" + model.ImageURL); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte); } return(RedirectToAction("Index")); } ModelState.AddModelError("FirstName", msg); model.Password = CommonHelper.Decrypt(model.Password); model.ConfirmPassword = model.Password; Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Create", model)); } catch (Exception ex) { model.Password = CommonHelper.Decrypt(model.Password); model.ConfirmPassword = model.Password; Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Create", model)); } }
public ActionResult SignUp(CustomerModels model) { try { if (!string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.ConfirmPassword) && !model.Password.Equals(model.ConfirmPassword)) { ModelState.AddModelError("ConfirmPassword", "Xác nhận mật khẩu không chính xác !"); } if (!ModelState.IsValid) { return(View(model)); } model.Password = CommonHelper.Encrypt(model.Password); string msg = ""; string cusId = ""; var result = _factory.CreateOrUpdate(model, ref cusId, ref msg); if (result) { var data = _factory.GetDetail(cusId); UserSession userSession = new UserSession(); userSession.Email = data.Email; userSession.UserName = data.FirstName + " " + data.LastName; userSession.FirstName = data.FirstName; userSession.LastName = data.LastName; userSession.Phone = data.Phone; userSession.Address = data.Address; userSession.UserId = data.ID; userSession.PostCode = data.Postcode; userSession.Country = data.Country; userSession.City = data.City; Session.Add("UserClient", userSession); string myObjectJson = JsonConvert.SerializeObject(userSession); //new JavaScriptSerializer().Serialize(userSession); HttpCookie cookie = new HttpCookie("UserClientCookie"); cookie.Expires = DateTime.Now.AddMonths(1); cookie.Value = Server.UrlEncode(myObjectJson); HttpContext.Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("Email", msg); return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("SignUp", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }