Ejemplo n.º 1
0
 public static void UpdateWarranty(this Warranty warranty, WarrantyViewModel warrantyVM)
 {
     warranty.ID          = warrantyVM.ID;
     warranty.Name        = warrantyVM.Name;
     warranty.Description = warrantyVM.Description;
     warranty.Status      = warrantyVM.Status;
 }
Ejemplo n.º 2
0
        public void Create(WarrantyViewModel warrantyVM)
        {
            var Warranty = new Warranty
            {
                WarrantyPeriod = warrantyVM.WarrantyName
            };

            unitOfWork.WarrantyRepository.Insert(Warranty);
            unitOfWork.Save();
        }
Ejemplo n.º 3
0
        public void Update(WarrantyViewModel warrantyVM)
        {
            var Warranty = new Warranty
            {
                WarrantyId     = warrantyVM.WarrantyId,
                WarrantyPeriod = warrantyVM.WarrantyName
            };

            unitOfWork.WarrantyRepository.Update(Warranty);
            unitOfWork.Save();
        }
Ejemplo n.º 4
0
        // GET: Warranty/Create
        public ActionResult Create(int assetId)
        {
            var viewModel  = new WarrantyViewModel();
            var assetModel = _assetService.GetById(assetId);

            if (assetModel == null)
            {
                return(HttpNotFound());
            }
            viewModel.Asset = Mapper.Map <Asset, AssetViewModel>(assetModel);

            return(View(viewModel));
        }
        // GET: Warranty/Details/5
        public ActionResult Details(int id = 0)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WarrantyViewModel details = warrantyService.GetById(id);

            if (details == null)
            {
                return(HttpNotFound());
            }
            return(View(details));
        }
        public ActionResult Edit(WarrantyViewModel warrantyVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add update logic here

                    warrantyService.Update(warrantyVM);
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
        public ActionResult Create(WarrantyViewModel warrantyVM)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    warrantyService.Create(warrantyVM);
                }


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 8
0
 public HttpResponseMessage Post(HttpRequestMessage request, WarrantyViewModel warrantyVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             Warranty newWarranty = new Warranty();
             newWarranty.UpdateWarranty(warrantyVm);
             var category = _warrantyService.Add(newWarranty);
             _warrantyService.SaveChanges();
             response = request.CreateResponse(HttpStatusCode.Created, category);
         }
         return response;
     }));
 }
Ejemplo n.º 9
0
        public ActionResult Create(WarrantyViewModel viewModel)
        {
            try
            {
                int endYear      = Convert.ToInt32(viewModel.EndDate.Year.ToString());
                int warrantyYear = Convert.ToInt32(viewModel.DateWarranty.Year.ToString());
                if (String.IsNullOrEmpty(viewModel.Reason) || String.IsNullOrEmpty(viewModel.Result) || endYear < 1970 || warrantyYear < 1970)
                {
                    return(View(viewModel));
                }
                DateTime endD        = Convert.ToDateTime(viewModel.EndDate.ToString());
                DateTime warrantyD   = Convert.ToDateTime(viewModel.DateWarranty.ToString());
                int      compareDate = DateTime.Compare(endD, warrantyD);
                if (compareDate <= 0)
                {
                    ModelState.AddModelError("EndDate", "EndDate must have a date greater than DateWarranty");
                    return(View(viewModel));
                }
                else
                {
                    var warranty = new Warranty()
                    {
                        Reason       = viewModel.Reason.Trim(),
                        EndDate      = viewModel.EndDate,
                        DateWarranty = viewModel.DateWarranty,
                        Result       = viewModel.Result.Trim(),
                        AssetID      = viewModel.Asset.ID,
                        Active       = true
                    };

                    _warrantyService.Add(warranty);
                    _warrantyService.SaveChanges();
                    SetAlert("Add Warranty success", "success");
                }
            }
            catch (Exception e)
            {
                SetAlert("Add Warranty error", "error");
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public HttpResponseMessage Put(HttpRequestMessage request, WarrantyViewModel warrantyVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var warrantyDb = _warrantyService.GetByID(warrantyVm.ID);
                    warrantyDb.UpdateWarranty(warrantyVm);
                    _warrantyService.Update(warrantyDb);
                    _warrantyService.SaveChanges();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                return response;
            }));
        }
Ejemplo n.º 11
0
        public ItemsPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new WarrantyViewModel();
        }