Example #1
0
        public Base DeleteItems(DeleteItemRequest request)
        {
            Base viewModel = new Base();

            try
            {
                // Check if there are all originIds
                bool          isMissing        = false;
                List <string> originIdsMissing = new List <string>();
                foreach (string originId in request.OriginIds)
                {
                    isMissing = false;
                    isMissing = !_dataContext.OR_Items
                                .Any(i => i.OriginId.Equals(originId));
                    if (isMissing)
                    {
                        originIdsMissing.Add(originId);
                    }
                }

                if (originIdsMissing.Count > 0)
                {
                    string exceptionMessage = string.Format("The following originIds are missing in the database. Check the data: {0}", string.Join(", ", originIdsMissing.ToArray()));
                    throw new Exception(exceptionMessage);
                }

                foreach (string originId in request.OriginIds)
                {
                    // before delete the item, i have to delete all the item properties
                    List <OR_Property> itemProperties = _dataContext.OR_Properties
                                                        .Where(p => p.RelatedOriginId.Equals(originId))
                                                        .ToList();
                    foreach (OR_Property propertyToDelete in itemProperties)
                    {
                        _dataContext.OR_Properties.DeleteOnSubmit(propertyToDelete);
                    }

                    // delete the item
                    OR_Item itemToDelete = _dataContext.OR_Items.Single(i => i.OriginId.Equals(originId));
                    _dataContext.OR_Items.DeleteOnSubmit(itemToDelete);
                }
                _dataContext.SubmitChanges();
            }
            catch (Exception exc)
            {
                viewModel.ResultInfo.Result       = Base.ResultInfoDto.ResultEnum.Error;
                viewModel.ResultInfo.ErrorMessage = exc.Message;
            }

            return(viewModel);
        }
Example #2
0
        public Base AddItem(AddItemRequest request)
        {
            Base viewModel = new Base();

            try
            {
                // Prendo l'originId del tipo di item
                OR_ItemType itemType = getItemType(request.ItemType);

                // Creo l'item
                string  itemOriginId = Guid.NewGuid().ToString();
                OR_Item item         = new OR_Item()
                {
                    OriginId         = itemOriginId,
                    ItemTypeOriginId = itemType.OriginId,
                    LastEditDate     = DateTime.Now,
                    CreationDate     = DateTime.Now
                };
                _dataContext.OR_Items.InsertOnSubmit(item);
                _dataContext.SubmitChanges();

                // Per ogni input creo la relativa property
                foreach (AddItemRequest.Input input in request.Inputs)
                {
                    string      propertyOriginId = Guid.NewGuid().ToString();
                    OR_Property property         = new OR_Property()
                    {
                        OriginId        = propertyOriginId,
                        RelatedOriginId = item.OriginId,
                        Name            = input.Name,
                        Value           = input.Value
                    };
                    _dataContext.OR_Properties.InsertOnSubmit(property);
                }

                // NB. Gli input vengono aggiornati automaticamente al submit
                _dataContext.SubmitChanges();
            }
            catch (Exception exc)
            {
                viewModel.ResultInfo.Result       = Base.ResultInfoDto.ResultEnum.Error;
                viewModel.ResultInfo.ErrorMessage = exc.Message;
            }

            return(viewModel);
        }
Example #3
0
 partial void UpdateOR_Item(OR_Item instance);
Example #4
0
 partial void DeleteOR_Item(OR_Item instance);
Example #5
0
 partial void InsertOR_Item(OR_Item instance);