示例#1
0
		public async Task<Beacon> AddAsync(BeaconDto beaconDto)
		{
			var beacon = _converter.ConvertDtoToBeacon(beaconDto);
			_context.Add(beacon);
			await _context.SaveChangesAsync();
			return beacon;
		}
示例#2
0
        public BeaconDto Update(BeaconDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            Beacon beacon = Db.Beacons.FirstOrDefault(m => m.Id == dto.Id);

            if (beacon == null)
            {
                NotFoundException();
            }

            beacon.Name         = dto.Name;
            beacon.Description  = dto.Description;
            beacon.ModifiedDate = DateTime.UtcNow;
            beacon.IsDeleted    = dto.IsDeleted;
            beacon.Coord_X      = dto.Coord_X;
            beacon.Coord_Y      = dto.Coord_Y;
            beacon.MAC_address  = dto.MAC_address;
            beacon.Visits       = dto.Visits;

            Db.SaveChanges();

            return(Mapper.Map <BeaconDto>(beacon));
        }
示例#3
0
        public BeaconDto Create(BeaconDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            Beacon beacon = new Beacon
            {
                Name         = dto.Name,
                Description  = dto.Description,
                Coord_X      = dto.Coord_X,
                Coord_Y      = dto.Coord_Y,
                MAC_address  = dto.MAC_address,
                Visits       = dto.Visits,
                CreatedDate  = DateTime.UtcNow,
                ModifiedDate = DateTime.UtcNow,
                IsDeleted    = false
            };

            Db.Beacons.Add(beacon);

            Db.SaveChanges();

            return(Mapper.Map <BeaconDto>(beacon));
        }
示例#4
0
 public BeaconDto Update([FromBody] BeaconDto dto)
 {
     try
     {
         return(new BeaconHandler(isTest).Update(dto));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#5
0
        public Beacon ConvertDtoToBeacon(BeaconDto beaconDto)
        {
            var beacon = new Beacon
            {
                Guid        = Guid.NewGuid(),
                Name        = beaconDto.Name,
                Description = beaconDto.Description,
                Status      = true
            };

            return(beacon);
        }
示例#6
0
        public async Task <IActionResult> AddAsync([FromBody] BeaconDto beacon)
        {
            try
            {
                var newBeacon = await _beaconService.AddAsync(beacon);

                string newUri = Url.Link("BeaconGet", new { guid = newBeacon.Guid });
                return(Created(newUri, newBeacon));
            } catch (Exception e)
            {
            }
            return(BadRequest());
        }
示例#7
0
        // GET: Beacons/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var       request = new HTTPrequest();
            BeaconDto beacon  = await request.Get <BeaconDto>("api/beacon/" + id);

            if (beacon == null)
            {
                return(HttpNotFound());
            }
            return(View(beacon));
        }
示例#8
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                var       request = new HTTPrequest();
                BeaconDto beacon  = await request.Get <BeaconDto>("api/beacon/" + id);

                await request.Delete("api/beacon/" + id);

                return(RedirectToAction("Index", new { recentAction = "Deleted", recentName = beacon.Name, recentId = beacon.Id }));
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#9
0
        public async Task <ActionResult> Edit(BeaconDto beacon)
        {
            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(beacon.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(beacon));
            }

            var request = new HTTPrequest();

            if (ModelState.IsValid)
            {
                await request.Put <ArtefactCategoryDto>("api/beacon", beacon);

                return(RedirectToAction("Index", new { recentAction = "Editted", recentName = beacon.Name, recentId = beacon.Id }));
            }
            return(View(beacon));
        }
        private Node GetNodeFromBeaconDto(BeaconDto beaconDto)
        {
            NodeType nodeType;

            switch (beaconDto.Title)
            {
            case "S":
                nodeType = NodeType.Stairs;
                break;

            case "WC":
                nodeType = NodeType.WC;
                break;

            case "E":
                nodeType = NodeType.Elevator;
                break;

            case "L":
            case "L1":
            case "L2":
                nodeType = NodeType.Library;
                break;

            default:
                nodeType = NodeType.GenericRoom;
                break;
            }

            return(new Node(
                       id: beaconDto.Id,
                       title: beaconDto.Title,
                       description: beaconDto.Description,
                       beaconData: new BeaconData(
                           uuid: beaconDto.Uuid,
                           major: beaconDto.Major,
                           minor: beaconDto.Minor),
                       type: nodeType,
                       position: new PointU(beaconDto.CoordX, beaconDto.CoordY),
                       navigationId: beaconDto.NodeNumber));
        }
示例#11
0
        public async Task <ActionResult> Create(BeaconDto beacon)
        {
            // Checks Name is not Null or Empty
            if (string.IsNullOrEmpty(beacon.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(beacon));
            }

            if (ModelState.IsValid && (beacon.Name != null))
            {
                var request = new HTTPrequest();
                beacon = await request.Post <BeaconDto>("api/beacon", beacon);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = beacon.Name, recentId = beacon.Id }));
            }
            else
            {
                var request = new HTTPrequest();
                ViewBag.Action = null;

                return(View());
            }
        }