Esempio n. 1
0
 public IHttpActionResult Register(UserVM userVM)
 {
     if (ModelState.IsValid)
     {
         ErrorResponseVM errorResponse = authBL.CheckUsernameOrEmailExists(userVM);
         if (errorResponse.IsValid)
         {
             var isRegistered = authBL.Register(userVM);
             if (isRegistered)
             {
                 return(Ok());
             }
             else
             {
                 return(InternalServerError());
             }
         }
         else
         {
             return(BadRequest(JsonConvert.SerializeObject(errorResponse.Errors)));
         }
     }
     else
     {
         var validationResult = CustomDataAnnotation.ValidateEntity <UserVM>(userVM);
         return(BadRequest(JsonConvert.SerializeObject(validationResult.ValidationErrors)));
     }
 }
Esempio n. 2
0
 public IHttpActionResult SaveQuote(GetQuote quote)
 {
     if (ModelState.IsValid)
     {
         ErrorResponseVM errors = _quoteBL.ValidateGetQuote(quote);
         if (errors.IsValid)
         {
             string username = User.Identity.Name;
             bool   isAdded  = _quoteBL.AddQuote(quote, username);
             if (isAdded)
             {
                 return(Ok());
             }
             else
             {
                 return(InternalServerError());
             }
         }
         else
         {
             return(BadRequest(JsonConvert.SerializeObject(errors.Errors)));
         }
     }
     else
     {
         var validationResult = CustomDataAnnotation.ValidateEntity <GetQuote>(quote);
         return(BadRequest(JsonConvert.SerializeObject(validationResult.ValidationErrors)));
     }
 }
Esempio n. 3
0
        public ErrorResponseVM CheckUsernameOrEmailExists(UserVM userVM)
        {
            ErrorResponseVM errorRes         = new ErrorResponseVM();
            bool            isUsernameExists = _authDL.CheckUsernameExists(userVM.Username);

            if (isUsernameExists)
            {
                Error error = new Error()
                {
                    ErrorMessage = "Username Exists!",
                    Property     = "Username",
                };
                errorRes.Errors.Add(error);
            }
            bool isEmailExists = _authDL.CheckEmailExists(userVM.Email);

            if (isEmailExists)
            {
                Error error = new Error()
                {
                    ErrorMessage = "Email Exists!",
                    Property     = "Email"
                };
                errorRes.Errors.Add(error);
            }
            return(errorRes);
        }
Esempio n. 4
0
        public ErrorResponseVM ValidateGetQuote(GetQuote quote)
        {
            ErrorResponseVM errors = new ErrorResponseVM();

            if (!_carDL.CarExists(quote.CarId))
            {
                Error err = new Error()
                {
                    ErrorMessage = "Car with given CarId doesn't Exists!",
                    Property     = "CarId"
                };
                errors.Errors.Add(err);
            }
            if (!_mileageDL.CheckMileageExists(quote.MileageId))
            {
                Error err = new Error()
                {
                    ErrorMessage = "Mileage with given MileageId doesn't Exists!",
                    Property     = "MileageId"
                };
                errors.Errors.Add(err);
            }
            if (!_paybackTimeDL.CheckMonthsExists(quote.MonthId))
            {
                Error err = new Error()
                {
                    ErrorMessage = "PaybackTime with given PaybackTimeId doesn't Exists!",
                    Property     = "PaybackTime"
                };
                errors.Errors.Add(err);
            }
            return(errors);
        }
Esempio n. 5
0
 public IHttpActionResult AddBankDetails(GetUserBankDetails userVM)
 {
     if (ModelState.IsValid)
     {
         bool isExists = _userBL.CheckBankDetailsExists();
         if (!isExists)
         {
             ErrorResponseVM errors = _userBL.CheckAccountNoExists(userVM);
             if (errors.IsValid)
             {
                 bool isSuccess = _userBL.AddBankDetails(userVM);
                 if (isSuccess)
                 {
                     return(Ok());
                 }
                 else
                 {
                     return(InternalServerError());
                 }
             }
             else
             {
                 return(BadRequest(JsonConvert.SerializeObject(errors.Errors)));
             }
         }
         else
         {
             ErrorResponseVM errors = _userBL.CheckAccountNoExistsONUpdate(userVM);
             if (errors.IsValid)
             {
                 bool isSuccess = _userBL.UpdateBankDetails(userVM);
                 if (isSuccess)
                 {
                     return(Ok());
                 }
                 else
                 {
                     return(InternalServerError());
                 }
             }
             else
             {
                 return(BadRequest(JsonConvert.SerializeObject(errors.Errors)));
             }
         }
     }
     else
     {
         var validationResult = CustomDataAnnotation.ValidateEntity <GetUserBankDetails>(userVM);
         return(BadRequest(JsonConvert.SerializeObject(validationResult.ValidationErrors)));
     }
 }
Esempio n. 6
0
        public ErrorResponseVM CheckAccountNoExists(GetUserBankDetails userVM)
        {
            bool            isExists = _userDL.CheckAccountNoExists(userVM.AccountNo);
            ErrorResponseVM error    = new ErrorResponseVM();

            if (isExists)
            {
                Error err = new Error()
                {
                    ErrorMessage = "Account No Already Exists!",
                    Property     = "AccountNo"
                };
                error.Errors.Add(err);
            }
            return(error);
        }
Esempio n. 7
0
        public ErrorResponseVM CheckAccountNoExistsONUpdate(GetUserBankDetails userVM)
        {
            string          username = HttpContext.Current.User.Identity.Name;
            int             userId   = _userDL.GetUserId(username);
            bool            isExists = _userDL.CheckAccountNoExists(userId, userVM.AccountNo);
            ErrorResponseVM error    = new ErrorResponseVM();

            if (isExists)
            {
                Error err = new Error()
                {
                    ErrorMessage = "Account No Already Exists!",
                    Property     = "AccountNo"
                };
                error.Errors.Add(err);
            }
            return(error);
        }
Esempio n. 8
0
        public async Task <ActionResult> Register(UserVM user)
        {
            if (ModelState.IsValid)
            {
                AuthBL          auth     = new AuthBL();
                ErrorResponseVM response = await auth.RegisterAsync(user);

                if (response.IsValid)
                {
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ViewData["Errors"] = response.Errors;
                }
            }
            return(View());
        }
Esempio n. 9
0
        public async Task <ErrorResponseVM> RegisterAsync(UserVM user)
        {
            using (var client = new HttpClient())
            {
                var errorRes = new ErrorResponseVM();
                client.BaseAddress = new Uri("http://localhost:52778/");
                var                 content  = JsonConvert.SerializeObject(user);
                HttpContent         c        = new StringContent(content, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync("api/auth", c);

                if (!response.IsSuccessStatusCode)
                {
                    var result = response.Content.ReadAsStringAsync().Result;
                    var obj    = JsonConvert.DeserializeObject <ErrorRes>(result);
                    errorRes.Errors = JsonConvert.DeserializeObject <Error[]>(obj.Message).ToList();
                }
                return(errorRes);
            }
        }