Ejemplo n.º 1
0
        public IActionResult AddObservation([FromBody] ObservationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (model.Longitude > 180)
            {
                model.Longitude = (model.Longitude + 180) % 360 - 180;
            }
            else if (model.Longitude < -180)
            {
                model.Longitude = (model.Longitude - 180) % 360 + 180;
            }

            var accountId = int.Parse(User.Claims.FirstOrDefault(c => c.Type == "id").Value);

            var observation = new Observation
            {
                Description = model.Description,
                Latitude    = model.Latitude,
                Longitude   = model.Longitude,
                SpeciesId   = model.SpeciesId,
                Date        = model.Date,
                AccountId   = accountId
            };

            _context.Observations.Add(observation);

            _context.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(IFormCollection data, IFormFile imageFile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var extension = Path.GetExtension(imageFile.FileName);

            if (extension == null || !_allowedExtensions.Contains(extension))
            {
                return(BadRequest());
            }

            var fileName = $"{data["LatinName"]}{extension}";

            await SaveFile(imageFile, fileName);

            var species = new Database.Entities.Species()
            {
                RussianName    = data["RussianName"],
                LatinName      = data["LatinName"],
                OrderId        = int.Parse(data["OrderId"]),
                BelarusianName = data["BelarusianName"],
                Category       = int.Parse(data["Category"]),
                Description    = data["Description"],
                ImageFileName  = fileName,
            };

            _context.Species.Add(species);
            _context.SaveChanges();

            species.Order = _context.Orders.FirstOrDefault(t => t.Id == species.OrderId);
            return(new JsonResult(species));
        }
Ejemplo n.º 3
0
        public IActionResult AddAccountRole(int accountId, int roleId)
        {
            _context.AccountRoles.Add(new AccountRole()
            {
                AccountId = accountId,
                RoleId    = roleId
            });
            _context.SaveChanges();

            return(Ok());
        }
        public IActionResult Create([FromBody] SpeciesTypeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var speciesType = new SpeciesType()
            {
                Name        = model.Name,
                Description = model.Description
            };

            _context.SpeciesTypes.Add(speciesType);
            _context.SaveChanges();

            return(new JsonResult(speciesType));
        }
Ejemplo n.º 5
0
        public IActionResult Create([FromBody] ClassModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var newClass = new Class()
            {
                Name          = model.Name,
                LatinName     = model.LatinName,
                Description   = model.Description,
                SpeciesTypeId = model.SpeciesTypeId,
            };

            _context.Classes.Add(newClass);
            _context.SaveChanges();

            newClass.SpeciesType = _context.SpeciesTypes.FirstOrDefault(st => st.Id == newClass.SpeciesTypeId);

            return(new JsonResult(newClass));
        }
Ejemplo n.º 6
0
        public IActionResult Create([FromBody] OrderModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var order = new Order()
            {
                Name        = model.Name,
                LatinName   = model.LatinName,
                Description = model.Description,
                ClassId     = model.ClassId,
            };

            _context.Orders.Add(order);
            _context.SaveChanges();

            order.Class = _context.Classes.FirstOrDefault(c => c.Id == order.ClassId);

            return(new JsonResult(order));
        }