Beispiel #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;
 }
Beispiel #2
0
        public void Create(WarrantyViewModel warrantyVM)
        {
            var Warranty = new Warranty
            {
                WarrantyPeriod = warrantyVM.WarrantyName
            };

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

            unitOfWork.WarrantyRepository.Update(Warranty);
            unitOfWork.Save();
        }
Beispiel #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());
            }
        }
Beispiel #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;
     }));
 }
Beispiel #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"));
        }
Beispiel #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;
            }));
        }
        public ItemsPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new WarrantyViewModel();
        }