示例#1
0
        public ActionResult UploadFiles(string key)
        {
            if (!IsKeyForProfile(key))
            {
                throw new KatushaNotAllowedException(KatushaProfile, KatushaUser, key);
            }
            string description = Request.Form["description[]"];

            if (String.IsNullOrWhiteSpace(description))
            {
                description = "";
            }
            var list = new List <ViewDataUploadFilesResult>();

            foreach (string file in Request.Files)
            {
                var hpf = Request.Files[file];
                var viewDataUploadResult = _photosService.AddPhoto(KatushaProfile.Id, description, hpf);
                if (hpf != null)
                {
                    if (hpf.ContentLength != 0 && hpf.FileName != null)
                    {
                        list.Add(viewDataUploadResult);
                    }
                }
            }
            return(new ContentResult {
                Content = new JavaScriptSerializer {
                    MaxJsonLength = Int32.MaxValue
                }.Serialize(list),
                ContentType = "application/json"
            });
        }
 private ActionResult _Register(RegisterModel model, ActionResult successResult, ActionResult failResult)
 {
     if (ModelState.IsValid)
     {
         var hasError = false;
         if (model.Photo == null || model.Photo.ContentLength <= 0)
         {
             ModelState.AddModelError("Photo", "You must add a photo");
             hasError = true;
         }
         if ((byte)model.Gender <= 0 || (byte)model.Gender > 2)
         {
             ModelState.AddModelError("gender2", "You must select a gender");
             hasError = true;
         }
         if (String.IsNullOrWhiteSpace(model.Location.CountryCode))
         {
             ModelState.AddModelError("Location.CountryName", "You must select a country");
             hasError = true;
         }
         if (!hasError)
         {
             KatushaMembershipCreateStatus createStatus;
             KatushaUser = UserService.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
             if (createStatus == KatushaMembershipCreateStatus.Success)
             {
                 var profile = Mapper.Map <Profile>(model);
                 profile.UserId = KatushaUser.Id;
                 profile.Guid   = KatushaUser.Guid;
                 ProfileService.CreateProfile(profile);
                 KatushaProfile = profile;
                 _photoService.AddPhoto(profile.Id, "", model.Photo);
                 FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                 return(successResult);
             }
             ModelState.AddModelError("", ErrorCodeToString(createStatus));
         }
     }
     return(failResult);
 }