示例#1
0
        protected bool ValidateUser(User user)
        {
            // Validate Address
            if (user.Address.Trim().Length > 50)
                _validationDictionary.AddErrors("Address", "Address cannot exceeds 50 characters.");
            // Validate Phone
            //Todo
            // Validate Image
            //Todo
            // Validate Categories
            foreach (var item in user.Categories)
            {
                var category = _categoryRespository.Get(item.ID);
                if (category == null)
                {
                    _validationDictionary.AddErrors("Categories", "Category is not valid");
                    break;
                }
            }

            return _validationDictionary.IsValid;
        }
示例#2
0
        public async Task<bool> DeleteEventAsync(int id, string username)
        {
            // Validate not found
            var @event = await _respository.GetAsync(id);
            if (@event == null)
            {
                _validationDictionary.AddErrors("Event", "Not found.");
                return false;
            }

            // Validate authorization
            var user = await _respository.GetMasterAsync(@event);
            if (!user.Username.Trim().Equals(username.Trim()))
            {
                _validationDictionary.AddErrors("Authorization", "User does not have permission.");
                return false;
            }

            var l = _userRespository.GetJoinedUser(@event);

            List<User> list = new List<User>();

            foreach (var item in l)
            {
                User u = new User
                {
                    ID = item.ID
                };
                list.Add(u);
            }

            // Database logic
            try
            {
                await _respository.DeleteEventAsync(@event);
            }
            catch
            {
                return false;
            }

            //Create notification
            foreach (var item in list)
            {
                User u = new User
                {
                    ID = item.ID
                };
                _notificationRespository.CreateNotification(u, "It's too bad!!! " + @event.Name + " has been cancelled.");
            }

            return true;
        }
示例#3
0
        public async Task<bool> UpdateUserAsync(User user, string username)
        {
            // Validate not found
            var u = await _respository.GetAsync(user.ID);
            if (u == null)
            {
                _validationDictionary.AddErrors("User", "Not found");
                return false;
            }

            // Validate authorization
            if (!u.Username.Trim().Equals(username.Trim()))
            {
                _validationDictionary.AddErrors("Authorization", "User does not have permission.");
                return false;
            }

            // Validate logic
            if (!ValidateUser(user))
                return false;

            // Database logic
            try
            {
                await _respository.UpdateUserAsync(user);
            }
            catch
            {
                return false;
            }
            return true;
        }
示例#4
0
        public async Task<bool> UpdateEventAsync(Event @event, string username)
        {
            // Validate not found
            var e = await _respository.GetAsync(@event.ID);
            if (e == null)
            {
                _validationDictionary.AddErrors("Event", "Not found");
                return false;
            }

            // Validate authorization
            var user = await _respository.GetMasterAsync(@event);
            if (!user.Username.Trim().Equals(username.Trim()))
            {
                _validationDictionary.AddErrors("Authorization", "User does not have permission.");
                return false;
            }

            // Validate logic
            if (!ValidateEvent(@event))
                return false;

            // Database logic
            try
            {
                await _respository.UpdateEventAsync(@event);
            }
            catch
            {
                return false;
            }

            //Create notification
            var list = _userRespository.GetJoinedUser(e);
            foreach (var item in list)
            {
                User u = new User
                {
                    ID = item.ID
                };
                await _notificationRespository.CreateNotificationAsync(u, "Hey guess what!!! " + e.Name + " has been updated, check it out now!");
            }

            return true;
        }