public async Task <ApiResponseResult> SaveGuestInfo(GuestInfoDTO Guest, AddressDTO address) { ApiResponseResult apiResponseResult = new ApiResponseResult(); try { apiResponseResult = await _userRepository.SaveGuestInfo(Guest, address); } catch (Exception exc) { throw exc; } return(apiResponseResult); }
public async Task <ApiResponseResult> SaveGuestInfo(GuestInfoDTO Guest, AddressDTO address) { User user = await getuser(Guest.email); ApiResponseResult apiresult = new ApiResponseResult(); if (user == null) { user = new User(); try { user.userPassword = "******"; user.firstName = Guest.firstName; user.lastName = Guest.lastName; user.userEmail = Guest.email; user.contact = Guest.phone; user.roleID = (Int32)Constant.User.GUEST_USER; user.joiningDate = DateTime.Now; user.street = address.street; user.state = address.state; user.userZipCode = address.zipCode; user.apartment = address.appartment; user.city = address.city; user.userAddress = address.street + "," + address.appartment + "," + address.city + "," + address.state + "," + address.zipCode; user.isActive = true; _context.Users.Add(user); await _context.SaveChangesAsync(); await SaveUserRole((Int32)Constant.User.GUEST_USER, user.userId); apiresult.ErrorCode = (int)Constant.Error.NO_ERROR; apiresult.data = user; apiresult.message = "Save Successfully"; } //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) //{ // apiresult.ErrorNo = (int)Constant.Error.ENTITY_EXCEPTION; // apiresult.Message = dbEx.Message; // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // //raise a new exception inserting the current one as the InnerException // } // } //} catch (Exception exce) { apiresult.ErrorCode = (int)Constant.Error.EXCEPTION; apiresult.message = exce.Message; } } else { apiresult.ErrorCode = (int)Constant.Error.GUEST_ALREADY_EXIST; apiresult.message = "Guest Already Exist"; } return(apiresult); }