Пример #1
0
        public async Task <ActionResult> Edit(PeripheralViewModel data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var peripheral = mapper.Map <Peripheral>(data);

                    await peripherialService.UpdatePeripheralAsync(peripheral);

                    await peripherialService.SaveChangesAsync();

                    TempData["success"] = true;
                    TempData["msg"]     = "Peripheral edited successfully";

                    return(RedirectToAction("Index"));
                }

                return(View(data));
            }
            catch
            {
                return(View(data));
            }
        }
Пример #2
0
        public async Task <IHttpActionResult> UpdateGatewayAsync([FromBody] PeripheralViewModel peripheralviewmodel)
        {
            try
            {
                if (peripheralviewmodel == null)
                {
                    return(new BadRequestError("PERIPHERAL OBJECT IS NULL"));
                }
                var peripheral = mapper.Map <Peripheral>(peripheralviewmodel);
                await peripheralService.UpdatePeripheralAsync(peripheral);

                var result = await peripheralService.SaveChangesAsync();

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #3
0
        public async Task <IHttpActionResult> AddPeripheralAsync([FromBody] PeripheralViewModel peripheralviewmodel)
        {
            try
            {
                if (peripheralviewmodel == null)
                {
                    return(new BadRequestError("PERIPHERAL OBJECT IS NULL"));
                }
                var peripheral     = mapper.Map <Peripheral>(peripheralviewmodel);
                var cantPeipherals = peripheralService.GetAllPeripheralsByGatewayIdAsync(peripheral.GatewayId).Result.Count();
                if (cantPeipherals >= 10)
                {
                    return(new ServerError("NO MORE THAT 10 PERIPHERAL DEVICES ARE ALLOWED FOR A GATEWAY"));
                }
                peripheralService.AddPeripheralAsync(peripheral);
                var result = await peripheralService.SaveChangesAsync();

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }