public ActionResult Update(UserCards card)
 {
     try
     {
         userCardRepository.Update(card);
         return(Ok(new { success = true, successMessage = "Write Sucessfully" }));
     }
     catch (Exception ex)
     {
         return(Ok(new { success = false, errorMessage = ex.GetBaseException() }));
     }
 }
예제 #2
0
        public ApiResponse <User> RegisterStoreAction(StoreRegistrationEntry storeRegistration)
        {
            ApiResponse <User> response = new ApiResponse <User>();
            bool accountExist;
            bool savedAccount;
            bool savedStore;
            bool storeExist;
            bool addedRoleToUser;
            Role adminRole;

            try
            {
                if (storeRegistration.Store is object &&
                    storeRegistration.Account is object &&
                    storeRegistration.User is object &&
                    storeRegistration.Store.HasAllRequieredFieldsForRegistration() && storeRegistration.Account.HasAllRequierdFields() && storeRegistration.User.HasId())
                {
                    //Store
                    storeExist = _StoreRepository.StoreExists(
                        storeRegistration.Store.StoreOwnerName,
                        storeRegistration.Store.StoreName,
                        storeRegistration.Store.Location !
                        );

                    if (storeExist)
                    {
                        storeRegistration.Store.DateUpdated = DateTime.UtcNow;
                        savedStore = _StoreRepository.Update(storeRegistration.Store);
                    }
                    else
                    {
                        storeRegistration.Store.DateCreated = DateTime.UtcNow;
                        savedStore = _StoreRepository.Add(storeRegistration.Store);
                    }

                    // Card
                    accountExist = _CardRepo.CardExist(storeRegistration.Account.Id);

                    storeRegistration.Account.MyUserId  = storeRegistration.User.Id;
                    storeRegistration.Account.MyStoreId = storeRegistration.Store.Id;

                    if (accountExist)
                    {
                        savedAccount = _CardRepo.Update(storeRegistration.Account);
                    }
                    else
                    {
                        savedAccount = _CardRepo.Add(storeRegistration.Account);
                    }

                    // Role
                    adminRole = _UserRepo.GetAdminRole();
                    UsersRoles userRole = _RoleFactory.CreateUserRole(
                        userId: storeRegistration.User.Id,
                        storeId: storeRegistration.Store.Id,
                        roleId: adminRole.Id
                        );

                    addedRoleToUser = _UserRepo.AddUserRole(userRole);

                    if (savedAccount is false || savedStore is false || addedRoleToUser is false)
                    {
                        response.Failure.ErrorsMessages.Add($"Can't complete the registration process. Try again.");
                    }
                    else
                    {
                        response.Success.SuccessMessages.Add($"The registration if the store has been succesfull.");
                        response.Success.Data = _UserRepo.GetUserByEmailWithAll(storeRegistration.User.Email);

                        if (response.Success.Data.MyRoles is object)
                        {
                            foreach (var role in response.Success.Data.MyRoles)
                            {
                                role.User  = null;
                                role.Store = null;
                            }
                        }

                        if (response.Success.Data.MyStores is object)
                        {
                            foreach (var store in response.Success.Data.MyStores)
                            {
                                //store.
                            }
                        }
                    }
                }
                else
                {
                    response.Failure.ErrorsMessages.Add($"Can't complete the registration process due to uncompleted data.");
                }
            }
예제 #3
0
 public void Put([FromBody] CardAccount userCard)
 {
     UserCardRepo.Update(userCard);
 }