public async Task SelectRestReqScheItem(List <RestItemsListDto> input, int RestRequestsId, int?RestSchedulesId, int?RestInfosID)
        {
            try
            {
                if (input.Count() > 0)
                {
                    for (int i = 0; i < input.Count(); i++)
                    {
                        if (input[i].Count > 0)
                        {
                            RestScheduleItem ScheduleItem = _RestScheduleItemRepository.GetAll().Where(a => a.RestItemsId == input[i].Id && a.RestSchedulesId == RestSchedulesId).FirstOrDefault();

                            if (ScheduleItem != null)
                            {
                                var reqitem = new RestRequestItem();

                                reqitem.RestScheduleItemsId = ScheduleItem.Id;
                                reqitem.RestRequestsId      = RestRequestsId;
                                reqitem.Count = input[i].Count;

                                await _RestRequestItemRepository.InsertAsync(reqitem);
                            }
                            else
                            {
                                RestNonSchItem RestNonSchItem = _RestNonSchItemRepository.GetAll().Where(a => a.RestItemId == input[i].Id && a.RestInfoID == RestInfosID).FirstOrDefault();


                                var reqitem = new RestRequestItem();

                                reqitem.RestNonSchItemId = RestNonSchItem.Id;
                                reqitem.RestRequestsId   = RestRequestsId;
                                reqitem.Count            = input[i].Count;

                                await _RestRequestItemRepository.InsertAsync(reqitem);
                            }
                        }
                        await CurrentUnitOfWork.SaveChangesAsync();
                    }
                }
            }
            catch (DbUpdateException e)
            {
                SqlException s = e.InnerException.InnerException as SqlException;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        public async Task UnAttachRestScheItem(List <RestItemsListDto> selecteditem, int RestSchedulesId)
        {
            try
            {
                var RestSchesItem = _RestScheduleItemRepository.GetAll().Where(a => a.RestSchedulesId == RestSchedulesId).ToList();

                List <RestScheduleItem> RestScheItemListDtos = ObjectMapper.Map <List <RestScheduleItem> >(RestSchesItem);

                if (selecteditem != null)
                {
                    if (selecteditem.Count > 0)
                    {
                        for (int i = 0; i < selecteditem.Count(); i++)
                        {
                            RestScheduleItem add = RestScheItemListDtos.Find(a => a.RestItemsId == selecteditem[i].Id);

                            if (add == null)
                            {
                                RestScheduleItem item = new RestScheduleItem();
                                item.RestSchedulesId = RestSchedulesId;
                                item.RestItemsId     = selecteditem[i].Id;

                                await _RestScheduleItemRepository.InsertAsync(item);
                            }
                        }
                    }
                }
                if (RestScheItemListDtos != null)
                {
                    if (RestScheItemListDtos.Count() > 0)
                    {
                        for (int i = 0; i < RestScheItemListDtos.Count(); i++)
                        {
                            RestItemsListDto remove = selecteditem.Find(a => a.Id == RestScheItemListDtos[i].RestItemsId);

                            if (remove == null)
                            {
                                await _RestScheduleItemRepository.DeleteAsync(RestScheItemListDtos[i].Id);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 3
0
        public async Task AttachRestScheItem(List <RestItemsListDto> selecteditem, int RestSchedulesId)
        {
            if (selecteditem != null)
            {
                if (selecteditem.Count > 0)
                {
                    for (int i = 0; i < selecteditem.Count(); i++)
                    {
                        RestScheduleItem item = new RestScheduleItem();
                        item.RestSchedulesId = RestSchedulesId;
                        item.RestItemsId     = selecteditem[i].Id;

                        await _RestScheduleItemRepository.InsertAsync(item);
                    }
                }
            }
        }