コード例 #1
0
        public Result <ArticleDto> Add(ArticleDto article)
        {
            try
            {
                Articles newArticle;
                using (db = new SuperZapatosContext())
                {
                    newArticle = new Articles()
                    {
                        Id             = article.Id,
                        Name           = article.Name.Trim(),
                        Description    = article.Description.Trim(),
                        Price          = article.Price,
                        Store_Id       = article.Store_Id,
                        Total_in_shelf = article.Total_in_shelf,
                        Total_in_vault = article.Total_in_vault
                    };
                    newArticle = db.Articles.Add(newArticle);
                    article.Id = newArticle.Id;
                    if (db.SaveChanges() > 0)
                    {
                        return new Result <ArticleDto>
                               {
                                   Response      = article,
                                   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
                    }
                });
            }
        }
コード例 #2
0
ファイル: StoresBL.cs プロジェクト: cavimora/PruebaGap
        public Result <StoreDto> Update(StoreDto store)
        {
            try
            {
                using (db = new SuperZapatosContext())
                {
                    Store obj = db.Store.Find(store.Id);

                    if (obj != null)
                    {
                        obj.Name = store.Name.Trim();

                        obj.Address = store.Address.Trim();
                        if (db.SaveChanges() > 0)
                        {
                            return(new Result <StoreDto>
                            {
                                Response = new StoreDto {
                                    Id = obj.Id, Address = obj.Address.Trim(), Name = obj.Name.Trim()
                                },
                                Success = true,
                                TotalElements = 1,
                                Error = null
                            });
                        }
                    }
                }
                return(new Result <StoreDto>
                {
                    Response = null,
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 404, ErrorMsg = "Not Found"
                    }
                });
            }
            catch (Exception ex)
            {
                return(new Result <StoreDto>
                {
                    Response = null,
                    Success = false,
                    TotalElements = 0,
                    Error = new Error {
                        ErrorCode = 500, ErrorMsg = ex.Message
                    }
                });
            }
        }
コード例 #3
0
ファイル: StoresBL.cs プロジェクト: cavimora/PruebaGap
 public Result <StoreDto> Add(StoreDto store)
 {
     try
     {
         Store newStore;
         using (db = new SuperZapatosContext())
         {
             newStore = new Store()
             {
                 Address = store.Address.Trim(),
                 Name    = store.Name.Trim()
             };
             newStore = db.Store.Add(newStore);
             store.Id = newStore.Id;
             if (db.SaveChanges() > 0)
             {
                 return new Result <StoreDto>
                        {
                            Response      = store,
                            Success       = true,
                            TotalElements = 1,
                            Error         = null
                        }
             }
             ;
         }
         return(new Result <StoreDto>
         {
             Response = null,
             Success = false,
             TotalElements = 0,
             Error = new Error {
                 ErrorCode = 404, ErrorMsg = "Not Found"
             }
         });
     }
     catch (Exception ex)
     {
         return(new Result <StoreDto>
         {
             Response = null,
             Success = false,
             TotalElements = 0,
             Error = new Error {
                 ErrorCode = 500, ErrorMsg = ex.Message
             }
         });
     }
 }
コード例 #4
0
ファイル: StoresBL.cs プロジェクト: cavimora/PruebaGap
 public Result <bool> Delete(int id)
 {
     try
     {
         using (db = new SuperZapatosContext())
         {
             Store obj = db.Store.Find(id);
             if (obj != null)
             {
                 db.Store.Remove(obj);
                 if (db.SaveChanges() > 0)
                 {
                     return(new Result <bool>
                     {
                         Response = true,
                         Success = true,
                         TotalElements = 1,
                         Error = null
                     });
                 }
             }
         }
         return(new Result <bool>
         {
             Response = false,
             Success = false,
             TotalElements = 0,
             Error = new Error {
                 ErrorCode = 404, ErrorMsg = "Not Found"
             }
         });
     }
     catch (Exception ex)
     {
         return(new Result <bool>
         {
             Response = false,
             Success = false,
             TotalElements = 0,
             Error = new Error {
                 ErrorCode = 500, ErrorMsg = ex.Message
             }
         });
     }
 }
コード例 #5
0
ファイル: UnitOfWork.cs プロジェクト: ronbak/gapTest
 public void Commit()
 {
     _db.SaveChanges();
     _transaction.Complete();
 }
コード例 #6
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
                    }
                });
            }
        }