Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] Service data)
        {
            MonitorAPI.Data.Service Service = new Data.Service();
            var service = new Service();

            service.Link      = data.Link;
            service.TimeStamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");

            if (Service.GetStatus(service.Link))
            {
                service.Status = true;
            }
            else
            {
                service.Status = false;
            }

            using (var db = new MonitorContext())
            {
                db.Services.Add(service);
                await db.SaveChangesAsync();
            }

            return(CreatedAtAction("GetService", new { id = service.Id }, service));
        }
Beispiel #2
0
        public async Task <IActionResult> Put(int id, Service data)
        {
            using (var db = new MonitorContext())
            {
                var service = db.Services.SingleOrDefault(s => s.Id == id);

                if (service == null)
                {
                    return(NotFound());
                }

                service.TimeStamp = DateTime.Now.ToString("dd-MM-yyyyTHH:mm:sszzz");
                service.Link      = data.Link;

                MonitorAPI.Data.Service tester = new Data.Service();
                if (tester.GetStatus(service.Link))
                {
                    service.Status = true;
                }
                else
                {
                    service.Status = false;
                }

                db.Services.Update(service);
                await db.SaveChangesAsync();

                return(Ok(service));
            }
        }
        public dynamic GetAddons()
        {
            ServiceAddOnsResponse model = new ServiceAddOnsResponse();

            try
            {
                var          service_Add   = _db.Services.Where(a => a.IsAddOn == true).ToList();
                Data.Service serviceAddons = null;
                foreach (var item in service_Add)
                {
                    serviceAddons = new Data.Service();
                    serviceAddons.Service_Description = item.Service_Description;
                    serviceAddons.Service_Name        = item.Service_Name;
                    serviceAddons.Service_Price       = item.Service_Price;
                    serviceAddons.ServiceID           = item.ServiceID;
                    model.data.Add(serviceAddons);
                }
                model.Result = true;
                return(model.data);
            }
            catch (Exception ex)
            {
                model.Result          = false;
                model.ResponseMessage = ex.Message;
                return(model);
            }
        }
 public ActionResult DeleteConfirmed(int id)
 {
     Data.Service service = db.Services.Find(id);
     db.Services.Remove(service);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #5
0
        protected async Task HandleSubmit()
        {
            if (ServiceEditContext.Validate())
            {
                var service = (await ServiceService.GetAsync(
                                   x => x.ServiceTypeId == AdminServiceVM.SelectedService &&
                                   x.ServiceTypeDate.Equals(AdminServiceVM.Date), null, "ServiceType"))
                              .FirstOrDefault();
                if (service == null)
                {
                    service = new Data.Service
                    {
                        Price           = (decimal)AdminServiceVM.Price,
                        ServiceTypeDate = (DateTime)AdminServiceVM.Date,
                        IsActive        = true
                    };

                    if (AdminServiceVM.SelectedService > 0)
                    {
                        service.ServiceTypeId = AdminServiceVM.SelectedService;

                        var oldService = (await ServiceService.GetAsync(
                                              x => x.ServiceTypeId == AdminServiceVM.SelectedService &&
                                              x.IsActive,
                                              null, "ServiceType"))
                                         .FirstOrDefault();
                        if (oldService != null)
                        {
                            oldService.IsActive = false;
                            ServiceService.Update(oldService);
                        }
                    }
                    else
                    {
                        service.ServiceType = new Data.ServiceType
                        {
                            Name        = AdminServiceVM.ServiceName,
                            Description = AdminServiceVM.Description
                        };
                    }
                    await ServiceService.AddAsync(service);
                }
                else
                {
                    service.Price = (decimal)AdminServiceVM.Price;
                    ServiceService.Update(service);
                }
                await ServiceService.SaveChangesAsync(AppUser.Instance.FullName);
                await TableInitialiser();

                ToggleView();
            }
            await InvokeAsync(StateHasChanged);
        }
 // GET: Services/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Data.Service service = db.Services.Find(id);
     if (service == null)
     {
         return(HttpNotFound());
     }
     return(View(service));
 }
        public ActionResult Edit(Data.Service service)
        {
            ModelState.Remove("CreateDt");
            ModelState.Remove("CreatedBy");
            if (ModelState.IsValid)
            {
                service.CreatedBy       = "Admin";
                service.CreateDt        = DateTime.Now.Date;
                db.Entry(service).State = EntityState.Modified;
                db.SaveChanges();

                AddNotification(Models.NotifyType.Success, "Records Successfully Updated.", true);

                return(RedirectToAction("Index"));
            }
            return(View(service));
        }