Example #1
0
        public async Task <IActionResult> PostSecurity([FromBody] Models.Security newSecurity)
        {                                                       // could turn this into function in service file--> reusable. Can receive array of prices, but shouldnt
            if (String.IsNullOrEmpty(newSecurity.SecurityName)) // todo these checks need to be better
            {
                return(StatusCode(400, "Must provide security name."));
            }
            if (String.IsNullOrEmpty(newSecurity.ISIN))
            {
                return(StatusCode(400, "Must provide 12 digit security ISIN."));
            }
            if (String.IsNullOrEmpty(newSecurity.Country))
            {
                return(StatusCode(400, "Must provide country security belongs to."));
            }
            try
            {
                _securityContext.Securities.Add(newSecurity);
                await _securityContext.SaveChangesAsync();

                return(new OkObjectResult("Succesfully saved security"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(500, e));
            }
        }
Example #2
0
        public IActionResult Register(Dictionary <string, string> profile)
        {
            Models.Security    security   = new Models.Security();
            DatabaseConnection connection = new DatabaseConnection();

            try
            {
                if (CheckCredentials(profile))
                {
                    connection.AddUserToDatabase(profile["email"], security.Encrypt(profile["password"]));

                    ConcreteOwnerBuilder ownerBuilder = new ConcreteOwnerBuilder();
                    ownerBuilder.AddEmail(profile["email"]);
                    ownerBuilder.AddFirstName(profile["firstName"]);
                    ownerBuilder.AddSecondName(profile["secondName"]);
                    Random random = new Random();
                    ownerBuilder.AddID(random.Next(100, 999));

                    connection.AddOwnerToDatabase(ownerBuilder.BuildOwner());
                    return(new StatusCodeResult(StatusCodes.Status201Created));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (SqlException)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
        }
Example #3
0
        private void UpdateUI()
        {
            Items                = new ObservableCollection <Models.Database.Rfid>(_database.GetModel <LUCT.Models.Database.Rfid>());
            _itemsCount          = Items.Count;
            RfidData.ItemsSource = Items;

            _security     = _database.GetModel <Models.Security>()[0];
            banQuota.Text = _security.BanQuota.ToString();
            banTime.Text  = _security.BanTime.ToString();
        }
Example #4
0
 public async Task <IActionResult> Post([FromBody] Models.Security security)
 {
     try
     {
         _context.Securities.Add(security);
         _context.SaveChanges();
         return(new OkObjectResult("Succesfully saved todo"));
     }
     catch (Exception e)
     {
         //normally a log
         Console.WriteLine(e);
         return(new BadRequestObjectResult("No Luck"));
     }
 }
Example #5
0
        [HttpPatch]                                                  //should have an id in url?
        public async Task <IActionResult> UpdateSecurity([FromBody] Models.Security updatedSecurity)
        {                                                            //todo edit this update for proper fields.
          //Could add prices here, but bad practice
            if (String.IsNullOrEmpty(updatedSecurity.Id.ToString())) // this needs better detection
            {
                return(StatusCode(400, "Must provide id"));
            }
            try
            {
                var security = await _securityContext.Securities.FindAsync(updatedSecurity.Id);

                if (security == null)
                {
                    return(StatusCode(404));
                }

                if (!String.IsNullOrEmpty(updatedSecurity.SecurityName)) //prob a check above like Post to ensure no empty since Patch all, Put 1:n
                {
                    security.SecurityName = updatedSecurity.SecurityName;
                }
                if (!String.IsNullOrEmpty(updatedSecurity.ISIN))
                {
                    security.ISIN = updatedSecurity.ISIN;
                }
                if (!String.IsNullOrEmpty(updatedSecurity.Country))
                {
                    security.Country = updatedSecurity.Country;
                }

                await _securityContext.SaveChangesAsync();

                return(new OkObjectResult($"Succesfully updated: {security.SecurityName}"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(500, e));
            }
        }