Exemple #1
0
        public Result <ComplexArticles <List <ArticleDto> > > Get()
        {
            try
            {
                List <ArticleDto> articles;
                List <StoreDto>   stores;
                using (db = new SuperZapatosContext())
                {
                    articles = (from art in db.Articles
                                select new ArticleDto
                    {
                        Id = art.Id,
                        Name = art.Name.Trim(),
                        Description = art.Description.Trim(),
                        Price = art.Price,
                        Store_Id = art.Store_Id,
                        Total_in_shelf = art.Total_in_shelf,
                        Total_in_vault = art.Total_in_vault
                    }).ToList();

                    stores = (from sto in db.Store
                              select new StoreDto
                    {
                        Address = sto.Address,
                        Id = sto.Id,
                        Name = sto.Name
                    }).ToList();
                }
                if (articles.Count > 0)
                {
                    return new Result <ComplexArticles <List <ArticleDto> > >
                           {
                               Response = new ComplexArticles <List <ArticleDto> >
                               {
                                   Articles = articles,
                                   Stores   = stores
                               },
                               Success       = true,
                               TotalElements = articles.Count,
                               Error         = null
                           }
                }
                ;
                return(new Result <ComplexArticles <List <ArticleDto> > >
                {
                    Response = new ComplexArticles <List <ArticleDto> >
                    {
                        Articles = new List <ArticleDto>(),
                        Stores = stores
                    },
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 404, ErrorMsg = "Not Found"
                    }
                });
            }
            catch (Exception ex)
            {
                return(new Result <ComplexArticles <List <ArticleDto> > >
                {
                    Response = null,
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 500, ErrorMsg = ex.Message
                    }
                });
            }
        }
Exemple #2
0
 public UnitOfWork()
 {
     _db = new SuperZapatosContext();
 }
Exemple #3
0
        public Result <ArticleDto> Update(ArticleDto article)
        {
            try
            {
                using (db = new SuperZapatosContext())
                {
                    Articles obj = db.Articles.Find(article.Id);

                    if (obj != null)
                    {
                        obj.Id = article.Id;

                        obj.Name           = article.Name.Trim();
                        obj.Description    = article.Description.Trim();
                        obj.Price          = article.Price;
                        obj.Store_Id       = article.Store_Id;
                        obj.Total_in_shelf = article.Total_in_shelf;
                        obj.Total_in_vault = article.Total_in_vault;
                        if (db.SaveChanges() > 0)
                        {
                            return(new Result <ArticleDto>
                            {
                                Response = new ArticleDto
                                {
                                    Id = obj.Id,
                                    Name = obj.Name.Trim(),
                                    Description = obj.Description.Trim(),
                                    Price = obj.Price,
                                    Store_Id = obj.Store_Id,
                                    Total_in_shelf = obj.Total_in_shelf,
                                    Total_in_vault = obj.Total_in_vault
                                },
                                Success = true,
                                TotalElements = 1,
                                Error = null
                            });
                        }
                    }
                }
                return(new Result <ArticleDto>
                {
                    Response = null,
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 404, ErrorMsg = "Not Found"
                    }
                });
            }
            catch (Exception ex)
            {
                return(new Result <ArticleDto>
                {
                    Response = null,
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 500, ErrorMsg = ex.Message
                    }
                });
            }
        }