Exemplo n.º 1
0
        public async Task <ActionResult> Edit(CollectionPointVm data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var collectionPoint = await _db.CollectionPoints.FindAsync(data.CollectionPointId);

                        if (collectionPoint == null)
                        {
                            ModelState.AddModelError(ErrorMessage.DataNotFound, ErrorMessage.DataNotFound);
                        }
                        else
                        {
                            collectionPoint.Address          = data.Address;
                            _db.Entry(collectionPoint).State = EntityState.Modified;
                            await _db.SaveChangesAsync();

                            TempData["Success"] = SuccessMessage.Updated;
                            return(RedirectToAction("Index", "CollectionPoint", new { area = "ControlPanel", id = data.CollectionPointId }));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(data.CollectionPointId)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Add(CollectionPointVm data, HttpPostedFileBase categoryImage)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var collectionPoint = new CollectionPoint
                        {
                            Address = data.Address
                        };
                        _db.Entry(collectionPoint).State = EntityState.Added;
                        await _db.SaveChangesAsync();
                    }

                    TempData["Success"] = SuccessMessage.Added;
                    return(RedirectToAction("Index", "CollectionPoint", new { area = "ControlPanel" }));
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(0)));
        }