Ejemplo n.º 1
0
        public JsonResult CreateAccount(CreateAccountFormData newAccountInfo)
        {
            if (ModelState.IsValid)
            {
                var response = accountManager.CreateAccount(newAccountInfo);

                if (response.IsSuccess)
                {
                    return(Json(new { IsSuccess = true }));
                }

                else
                {
                    return(Json(new { IsSuccess = false, Error = response.Explanation }));
                }
            }
            else
            {
                string message = string.Empty;
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        message += error.ErrorMessage + "\n";
                    }
                }
                return(Json(new { IsSuccess = false, Error = message }));
            }
        }
        public IHttpActionResult CreateAccount(CreateAccountFormData newAccountInfo)
        {
            if (ModelState.IsValid)
            {
                var response = accountManager.CreateAccount(newAccountInfo);

                if (response.IsSuccess)
                {
                    return(Ok());
                }

                else
                {
                    return(BadRequest(response.Explanation));
                }
            }
            else
            {
                string message = string.Empty;
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        message += error.ErrorMessage + "\n";
                    }
                }
                return(BadRequest(message));
            }
        }
        public TransactionObject CreateAccount(CreateAccountFormData newAccountInfo)
        {
            TransactionObject response = new TransactionObject();

            if (userManager.IsUserExists(newAccountInfo.Username))
            {
                try
                {
                    Period period = prdManager.GetPeriod(newAccountInfo.Year, newAccountInfo.Term);

                    User    newUser    = new User();
                    Student newStudent = new Student();

                    newUser.Username     = newAccountInfo.Username;
                    newUser.CreationDate = DateTime.Now;
                    newUser.Password     = SecurityFolder.Security.GetEncryptedPassword(newAccountInfo.Password);//şifre hashlendi
                    newUser.ProfilePhoto = newAccountInfo.ProfilePhoto;
                    newUser.Email        = newAccountInfo.Email;

                    newStudent.Name     = newAccountInfo.Name;
                    newStudent.Surname  = newAccountInfo.Surname;
                    newStudent.Birthday = new DateTime(1996, 1, 1);
                    newStudent.Period   = period;

                    period.Students.Add(newStudent);

                    newUser.Student = newStudent;
                    newStudent.User = newUser;

                    userManager.AddUser(newUser);
                    stdManager.AddStudent(newStudent);


                    FriendRelationship fr = new FriendRelationship();
                    newUser.FriendRelationship = fr;

                    frManager.AddFriendRelationship(fr);


                    var saveResponse = uow.Save();

                    if (saveResponse.IsSuccess)
                    {
                        response.IsSuccess = true;
                    }
                    else
                    {
                        response.IsSuccess   = false;
                        response.Explanation = saveResponse.Explanation;
                    }
                }
                catch (Exception ex)
                {
                    response.IsSuccess   = false;
                    response.Explanation = base.GetExceptionMessage(ex);
                }
            }
            else
            {
                response.IsSuccess   = false;
                response.Explanation = "This username is exists! Please try valid username...";
            }
            return(response);
        }