Exemplo n.º 1
0
        public bool JoinUser(IConnectionHandler connectionHandler, Guid chipsFoodid, List <Guid> list)
        {
            var chipsFoodBo = new ChipsFoodBO();
            var food        = chipsFoodBo.Get(connectionHandler, chipsFoodid);

            if (food == null || food.Capacity == 0)
            {
                throw new Exception(Resources.Congress.Capacityisnotenough);
            }
            var chipsFoods = new ChipsFoodUserBO().Where(connectionHandler, x => x.ChipsFoodId == chipsFoodid);

            foreach (var guid in list)
            {
                var chipsFoodUser = new ChipsFoodUserBO().Get(connectionHandler, chipsFoodid, guid);
                if (chipsFoodUser == null)
                {
                    var foodUser = new ChipsFoodUser {
                        UserId = guid, ChipsFoodId = chipsFoodid
                    };
                    if (!new ChipsFoodUserBO().Insert(connectionHandler, foodUser))
                    {
                        throw new Exception(Resources.Congress.ErrorInSaveChipFood);
                    }
                    food.Capacity--;
                }
            }
            foreach (var chipsFood in chipsFoods)
            {
                if (list.All(x => x != chipsFood.UserId))
                {
                    if (!new ChipsFoodUserBO().Delete(connectionHandler, chipsFoodid, chipsFood.UserId))
                    {
                        throw new Exception(Resources.Congress.ErrorInSaveChipFood);
                    }
                    food.Capacity++;
                }
            }
            if (!chipsFoodBo.Update(connectionHandler, food))
            {
                throw new Exception(Resources.Congress.ErrorInSaveChipFood);
            }
            return(true);
        }
Exemplo n.º 2
0
        public bool Update(IConnectionHandler connectionHandler, ChipsFood chipsFood, List <int> days)
        {
            var chipsFoodBo = new ChipsFoodBO();
            var str         = string.Empty;

            foreach (var day in days)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    str += "-";
                }
                str += day;
            }
            chipsFood.DaysInfo = str;
            if (!chipsFoodBo.Update(connectionHandler, chipsFood))
            {
                throw new Exception(Resources.Congress.ErrorInUpdateChipFood);
            }

            return(true);
        }