Exemplo n.º 1
0
        public IActionResult Delete(int id)
        {
            var home = repository.FindById(id);

            repository.Delete(home);
            var homes = repository.GetAll().Select(x => HomeViewModel.MapHomeToHomeViewModel(x));

            return(PartialView("Homes", homes));
        }
Exemplo n.º 2
0
        protected override void DoDelete(Client currentClient, int id, object param)
        {
            Home home = repo.GetHomeById(id, currentClient.Id);

            if (home == null)
            {
                validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Home>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST);
                throw new ManahostValidationException(validationDictionnary);
            }
            if (currentClient.DefaultHomeId == id)
            {
                currentClient.DefaultHomeId = null;
                repo.Update <Client>(currentClient);
            }
            repo.Delete(home);
            repo.Save();
        }
Exemplo n.º 3
0
        public MessageReport Delete(string _id)
        {
            var rp = new MessageReport();

            try
            {
                var query = Builders <Home> .Filter.Eq(e => e._id, _id);

                _HomeRepository.Delete(query);
                rp.Success = true;
                rp.Message = "Delete Home Successfully";
            }
            catch (Exception ex)
            {
                rp.Message = ex.Message;
            }
            return(rp);
        }
Exemplo n.º 4
0
 public ActionResult Delete(string sIds)
 {
     try
     {
         if (Request.IsAjaxRequest())
         {
             int iCheck = objHomeRep.Delete(sIds, Delete_SQL);
             JsonResult(iCheck > 0);
         }
         else
         {
             NotAjaxJsonResult();
         }
     }
     catch (Exception Ex)
     {
         ExcetionJsonResult(Ex.Message);
     }
     return(jSONResult);
 }
        //User request to quit home
        public async Task LeaveHomeAsync(UserModel user, int newAdminId)
        {
            if (user.Position == (int)UserPosition.HasNotHome)
            {
                CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                errors.AddError("Home Not Exist", "User is not member of a home");
                errors.Throw();
            }

            Task <InformationModel> firstNameInfo = _informationRepository.GetInformationByInformationNameAsync("FirstName");
            Task <InformationModel> lastNameInfo  = _informationRepository.GetInformationByInformationNameAsync("LastName");

            user = await _userRepository.GetByIdAsync(user.Id, true);

            HomeModel home = await _homeRepository.GetByIdAsync(user.Home.Id, true);

            UserInformationModel userFirstName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await firstNameInfo).Id);

            UserInformationModel userLastName = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await lastNameInfo).Id);

            List <UserExpenseModel> userExpenses = await _userExpenseRepository.GetAllUserExpenseByUserIdAsync(user.Id);

            foreach (var ue in userExpenses)
            {
                _userExpenseRepository.Delete(ue);
            }

            if (home.Users.Count != 1)
            {
                if (user.Position == (int)UserPosition.Admin)
                {
                    UserModel newAdmin = await _userRepository.GetByIdAsync(newAdminId);

                    if (newAdmin == null || newAdmin.Home.Id != user.Home.Id)
                    {
                        CustomException errors = new CustomException((int)HttpStatusCode.BadRequest);
                        errors.AddError("Friendship Not Found", "Friendship not found for admin assignment");
                        errors.Throw();
                    }
                    newAdmin.Position = (int)UserPosition.Admin;
                    home.Admin        = newAdmin;
                }

                home.Users.Remove(user);
                user.Home     = null;
                user.Position = (int)UserPosition.HasNotHome;

                _homeRepository.Update(home);
                _userRepository.Update(user);

                //Home friends notification
                foreach (var u in home.Users)
                {
                    FriendshipModel friendship = await _friendshipRepository.GetFriendshipByIdAsync(user.Id, u.Id);

                    FCMModel fcm = new FCMModel(u.DeviceId, new Dictionary <string, object>());
                    fcm.notification.Add("title", "Evden Ayrılma");

                    if (friendship.User1.Id == user.Id)
                    {
                        if (friendship.Debt > 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Alacağınız : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       friendship.Debt));
                        }
                        else if (friendship.Debt == 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz veya alacağınız bulunmamaktadır.", userFirstName.Value,
                                                                       userLastName.Value));
                        }
                        else
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       -friendship.Debt));
                        }
                    }
                    else
                    {
                        if (friendship.Debt > 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       friendship.Debt));
                        }
                        else if (friendship.Debt == 0)
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Borcunuz veya alacağınız bulunmamaktadır.", userFirstName.Value,
                                                                       userLastName.Value));
                        }
                        else
                        {
                            fcm.notification.Add("body", String.Format("{0} {1} evden ayrılıyor. Alacağınız : {2:c}", userFirstName.Value,
                                                                       userLastName.Value,
                                                                       -friendship.Debt));
                        }
                    }

                    await _fcmService.SendFCMAsync(fcm);

                    fcm = new FCMModel(u.DeviceId, type: "LeaveHome");

                    fcm.data.Add("LeaverId", user.Id);
                    await _fcmService.SendFCMAsync(fcm);

                    _friendshipRepository.Delete(friendship);
                }
            }
            else
            {
                ShoppingListModel shoppingList = await _shoppingListRepository.GetShoppingListByHomeIdAsync(user.Home.Id);

                List <NotepadModel> notepad = await _notepadRepository.GetAllNoteByHomeIdAsync(user.Home.Id);

                List <ExpenseModel> expenses = await _expenseRepository.GetAllExpensesByHomeIdAsync(user.Home.Id);

                _shoppingListRepository.Delete(shoppingList);

                foreach (var note in notepad)
                {
                    _notepadRepository.Delete(note);
                }

                foreach (var expense in expenses)
                {
                    _expenseRepository.Delete(expense);
                }

                user.Home     = null;
                user.Position = (int)UserPosition.HasNotHome;

                _userRepository.Update(user);
                _homeRepository.Delete(home);
            }
        }
Exemplo n.º 6
0
 public void Delete(HomeDTO entidad)
 {
     _homeRepository.Delete(Mapper.Map <HomeDTO, Home>(entidad));
     _homeRepository.UnitOfWork.Complete();
 }
Exemplo n.º 7
0
 public void Delete(Home t)
 {
     //İş kurulları uygulanacak
     _homerepository.Delete(t);
 }
Exemplo n.º 8
0
 public void Delete(long id)
 {
     _homeRepository.Delete(id);
 }