public async Task <ActionResult> UpdatePhotoUser() { long idUser = long.Parse(User.Identity.GetUserId()); try { HttpPostedFileBase file = Request.Files[0]; if (file != null) { long result = await SaveImageForUser(file, idUser); MediaContent CurrentMediaId = cms_db.GetObjMedia().Where(s => s.ObjTypeId == (int)EnumCore.ObjTypeId.nguoi_dung && s.ContentObjId == idUser).FirstOrDefault(); string userPhotoUrl = "/Media/no_photo.png"; if (CurrentMediaId != null) { userPhotoUrl = CurrentMediaId.FullURL; } return(Json("{\"photo_url\": \"" + userPhotoUrl + "\", \"result\": \"1\"}")); } else { return(Json("{\"photo_url\": \"" + "/Media/no_photo.png" + "\", \"result\": \"0\"}")); } } catch (Exception ex) { DataModel.DataStore.Core core = new DataModel.DataStore.Core(); core.AddToExceptionLog("UpdatePhotoUser", "AccountController", "Upload photo Error: " + ex.Message, idUser); return(Json("{\"photo_url\": \"" + "/Media/no_photo.png" + "\", \"result\": \"0\"}")); } }
public ActionResult Index() { try { IndexViewModel model = new IndexViewModel(); long[] lstContentid = cms_db.GetlstContentPackageIquery().Where(s => s.ContentType == (int)EnumCore.ObjTypeId.tin_tuc && s.PackageId == 1).OrderByDescending(s => s.ContentId).Select(s => s.ContentId).Take(30).ToArray(); model.lstNews = cms_db.GetlstContentItem().Where(s => lstContentid.Contains(s.ContentItemId) && s.StateId != (int)EnumCore.StateType.da_xoa).OrderByDescending(d => d.ContentItemId).Take(3).ToList(); model.crypto = this.GetDatPageInforViewModelaPageInfor((int)ConstFrontEnd.FrontendPageinfor.crypto); model.indexvideo = this.GetDatPageInforViewModelaPageInfor((int)ConstFrontEnd.FrontendPageinfor.indexvideo); model.intro = this.GetDatPageInforViewModelaPageInfor((int)ConstFrontEnd.FrontendPageinfor.intro); model.trade = this.GetDatPageInforViewModelaPageInfor((int)ConstFrontEnd.FrontendPageinfor.trade); IPagedList <Package> _lstPackage = cms_db.GetlstPackage() .OrderBy(c => c.PackageId).ToPagedList(1, (int)EnumCore.BackendConst.page_size); foreach (var item in _lstPackage) { if (item.PackageId == 2) { ViewBag.Night1M = item.NewPrice; ViewBag.Night3M = item.NewPrice3M; ViewBag.NightForever = item.ForeverPrice; } if (item.PackageId == 3) { ViewBag.Silver1M = item.NewPrice; ViewBag.Silver3M = item.NewPrice3M; ViewBag.SilverForever = item.ForeverPrice; } if (item.PackageId == 4) { ViewBag.Gold1M = item.NewPrice; ViewBag.Gold3M = item.NewPrice3M; ViewBag.GoldForever = item.ForeverPrice; } if (item.PackageId == 5) { ViewBag.Diamond1M = item.NewPrice; ViewBag.Diamond3M = item.NewPrice3M; ViewBag.DiamondForever = item.ForeverPrice; } } return(View(model)); } catch (Exception e) { DataModel.DataStore.Core core = new DataModel.DataStore.Core(); core.AddToExceptionLog("UpdatePhotoUser", "AccountController", "Upload photo Error: " + e.Message); return(View()); } }
public ActionResult CropImage( string imagePath, int?cropPointX, int?cropPointY, int?imageCropWidth, int?imageCropHeight) { if (string.IsNullOrEmpty(imagePath) || !cropPointX.HasValue || !cropPointY.HasValue || !imageCropWidth.HasValue || !imageCropHeight.HasValue) { return(new HttpStatusCodeResult((int)System.Net.HttpStatusCode.BadRequest)); } byte[] imageBytes = System.IO.File.ReadAllBytes(Server.MapPath(imagePath)); byte[] croppedImage = cms_db.CropImage(imageBytes, cropPointX.Value, cropPointY.Value, imageCropWidth.Value, imageCropHeight.Value); long idUser = long.Parse(User.Identity.GetUserId()); try { if (croppedImage != null) { MediaContent CurrentMediaId = cms_db.GetObjMedia().Where(s => s.ObjTypeId == (int)EnumCore.ObjTypeId.nguoi_dung && s.ContentObjId == idUser).FirstOrDefault(); string userPhotoUrl = "~/" + CurrentMediaId.FullURL; System.IO.FileStream _FileStream = new System.IO.FileStream(Server.MapPath(userPhotoUrl), System.IO.FileMode.Create, System.IO.FileAccess.Write); _FileStream.Write(croppedImage, 0, croppedImage.Length); _FileStream.Close(); return(Json("{\"photo_url\": \"" + CurrentMediaId.FullURL + "\", \"result\": \"1\"}")); } else { return(Json("{\"photo_url\": \"" + "/Media/no_photo.png" + "\", \"result\": \"0\"}")); } } catch (Exception ex) { DataModel.DataStore.Core core = new DataModel.DataStore.Core(); core.AddToExceptionLog("UpdatePhotoUser", "AccountController", "Upload photo Error: " + ex.Message, idUser); return(Json("{\"photo_url\": \"" + "/Media/no_photo.png" + "\", \"result\": \"0\"}")); } }