コード例 #1
0
 public object GetById(int id)
 {
     if (BasicHttpAuth.IsAuthorized())
     {
         Article article;
         try
         {
             article = _articleService.GetById(id);
         }
         catch
         {
             throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.ServerError, HttpStatusCode.InternalServerError));
         }
         if (article == null)
         {
             throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.RecordNotFound, HttpStatusCode.NotFound));
         }
         return(new ArticleServiceSuccessVM()
         {
             Article = ArticleMappers.MapToVM(article), Total_elements = 1
         });
     }
     else
     {
         throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.NotAuthorized, HttpStatusCode.Unauthorized));
     }
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Price,Total_in_shelf,Total_in_vault,StoreId")] AddEditArticleVM article)
 {
     if (ModelState.IsValid)
     {
         var articleToEdit = ArticleMappers.MapToArticle(article);
         _articleService.Edit(articleToEdit);
         return(RedirectToAction("Index"));
     }
     return(View(article));
 }
コード例 #3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Article article = _articleService.GetById((int)id);

            if (article == null)
            {
                return(HttpNotFound());
            }

            return(View(ArticleMappers.MapToVM(article)));
        }
コード例 #4
0
        // GET: Articles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Article article = _articleService.GetById((int)id);

            if (article == null)
            {
                return(HttpNotFound());
            }
            var articleVM = ArticleMappers.MapToAddEditVM(article);

            ViewBag.Stores = new StoreService().GetAll().Select(x =>
                                                                new SelectListItem
            {
                Value = x.ID.ToString(),
                Text  = x.Name
            }).ToList();
            return(View(articleVM));
        }
コード例 #5
0
 public object Get()
 {
     if (BasicHttpAuth.IsAuthorized())
     {
         try
         {
             var articles = _articleService.GetAll();
             return(new ArticlesServiceSuccessVM()
             {
                 Articles = articles.Select(x => ArticleMappers.MapToVM(x)).ToList(), Total_elements = articles.Count
             });
         }
         catch
         {
             throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.ServerError, HttpStatusCode.InternalServerError));
         }
     }
     else
     {
         throw new HttpResponseException(CustomErrors.CreateErrorMessage(StatusErrorCodes.NotAuthorized, HttpStatusCode.Unauthorized));
     }
 }
コード例 #6
0
        // GET: Articles
        public ActionResult Index(int storeId = -1)
        {
            List <SelectListItem> storesSelectItems;
            List <ArticleVM>      model;

            var stores = _storeService.GetAll();

            if (stores.Count == 0)
            {
                storesSelectItems = new List <SelectListItem>();
            }
            else
            {
                storesSelectItems = stores.Select(x =>
                                                  new SelectListItem
                {
                    Value = x.ID.ToString(),
                    Text  = x.Name
                }).ToList();
                if (storeId == -1)
                {
                    storeId = stores.First().ID;
                }
            }
            ViewBag.Stores = storesSelectItems;

            var articles = _articleService.GetByStoreId(storeId);

            if (articles == null)
            {
                model = new List <ArticleVM>();
            }
            else
            {
                model = articles.Select(x => ArticleMappers.MapToVM(x)).ToList();
            }
            return(View(model));
        }