public BirthdayModel GetById(int Id)
        {
            BirthdayModel birthdayModel = new BirthdayModel();

            var sqlQuery = "SELECT * FROM Birthday WHERE Id = " + Id;

            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                using (var sqlConnection = new SqlConnection(_connectionString)) //já faz o close e dispose
                    using (var sqlCommand = new SqlCommand(sqlQuery, sqlConnection))
                    {
                        sqlCommand.CommandType = CommandType.Text;

                        sqlConnection.Open();

                        using (var reader = sqlCommand.ExecuteReader())
                        {
                            var idColumnIndex             = reader.GetOrdinal(nameof(BirthdayModel.Id));
                            var nomeColumnIndex           = reader.GetOrdinal(nameof(BirthdayModel.Nome));
                            var sobrenomeColumnIndex      = reader.GetOrdinal(nameof(BirthdayModel.Sobrenome));
                            var dataNascimentoColumnIndex = reader.GetOrdinal(nameof(BirthdayModel.DataNascimento));
                            while (reader.Read())
                            {
                                birthdayModel.Id             = reader.GetFieldValue <int>(idColumnIndex);
                                birthdayModel.Nome           = reader.GetFieldValue <string>(nomeColumnIndex);
                                birthdayModel.Sobrenome      = reader.GetFieldValue <string>(sobrenomeColumnIndex);
                                birthdayModel.DataNascimento = reader.GetFieldValue <DateTime>(dataNascimentoColumnIndex);
                            }
                        }
                    }
            }
            return(birthdayModel);
        }
        public override Task InitializeAsync(object navigationData)
        {
            _birthdayId = (int)navigationData;

            if (_birthdayId == 0)
            {
                Title = Resmgr.Value.GetString(ConstantsHelper.CreateBirthdayTitle, CultureInfo.CurrentCulture);
                SelectedBirthDateViewModel = BirthDateViewModels.FirstOrDefault();
            }
            else
            {
                _model                     = App.BirthdaysRepository.Value.GetBirthdayAsync(_birthdayId);
                Title                      = _model.Name;
                Name                       = _model.Name;
                ImageContent               = _model.ImageContent;
                AdditionalInfo             = _model.GiftDescription;
                SelectedBirthDateViewModel = BirthDateViewModels
                                             .FirstOrDefault(x => x.MonthNumber == _model.BirthDayDate.Month);

                OnAppearing();
                SelectedBirthDateViewModel.SelectDay(_model.BirthDayDate.Day);
            }

            return(base.InitializeAsync(navigationData));
        }
Beispiel #3
0
        public NotificationsModel GetNotifications()
        {
            string         BaseUrl = ConfigurationManager.ConnectionStrings["NotificationServerName"].ConnectionString;
            string         url     = BaseUrl + DestinationNames.GetNotifications;
            HttpWebRequest req     = (HttpWebRequest)HttpWebRequest.Create(url);

            req.Method = "GET";
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            using (Stream stream = resp.GetResponseStream())
            {
                BinaryFormatter    bf                 = new BinaryFormatter();
                var                sr                 = new StreamReader(stream);
                Notifications      notifications      = (Notifications)bf.Deserialize(stream);
                NotificationsModel notificationsModel = new NotificationsModel();
                foreach (Notification el in notifications.ListOfEvents)
                {
                    Models.NotificationModel item = new NotificationModel();
                    DateTime newDt = new DateTime(DateTime.Now.Year, el.Date.Month, el.Date.Day);
                    item.Date    = newDt;
                    item.Address = el.Address;
                    item.Type    = el.Type;
                    notificationsModel.ListOfEvents.Add(item);
                }
                foreach (Birthday el in notifications.ListOfBirthdays)
                {
                    BirthdayModel day = new BirthdayModel();
                    day.Date      = el.Date;
                    day.FirstName = el.FirstName;
                    day.LastName  = el.LastName;
                    notificationsModel.ListOfBirthdays.Add(day);
                }
                return(notificationsModel);
            }
        }
 public static Birthday MapToBirthday(BirthdayModel contractBirthday)
 {
     return(new Birthday
     {
         Id = contractBirthday.Id,
         Name = contractBirthday.Name,
         Birthdate = contractBirthday.Birthdate
     });
 }
Beispiel #5
0
 public void Save(BirthdayModel model)
 {
     if (model.Id != 0)
     {
         _db.InsertOrReplaceWithChildren(model);
     }
     else
     {
         _db.InsertWithChildren(model);
     }
 }
 public static BirthdayViewModel ToBirthdayViewModel(this BirthdayModel model)
 {
     return(new BirthdayViewModel
     {
         Id = model.Id,
         Name = model.Name,
         ImageContent = model.ImageContent,
         BirthDayDate = model.BirthDayDate,
         GiftDescription = model.GiftDescription
     });
 }
        public void Put(int id, [FromBody] BirthdayModel birthdayModel)
        {
            Birthday birthDay = _myService.GetMyEntities(bd => bd.Id == id).FirstOrDefault();

            if (birthDay != null)
            {
                birthDay.Birthdate = !string.IsNullOrWhiteSpace(birthdayModel.Birthdate.ToString("yyyy-mm-dd")) ? birthdayModel.Birthdate : birthDay.Birthdate;
                birthDay.Name      = !string.IsNullOrWhiteSpace(birthdayModel.Name) ? birthdayModel.Name : birthDay.Name;
                _myService.UpdateMyEntity(birthDay);
            }
        }
 public void Insert(BirthdayModel birthdayModel)
 {
     if (birthdayModel == null)
     {
         throw new ArgumentNullException("Error");
     }
     if (string.IsNullOrWhiteSpace(birthdayModel.Nome) || birthdayModel.Nome.Length < 3)
     {
         throw new ArgumentException("Nome da pessoa inválido");
     }
     _birthdayDB.Insert(birthdayModel);
 }
Beispiel #9
0
 public ActionResult Edit(BirthdayModel editBirthdayModel)
 {
     try
     {
         // TODO: Add update logic here
         _birthdayRepository.Update(editBirthdayModel);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #10
0
 public IActionResult Delete(BirthdayModel birthdayDelete)
 {
     try
     {
         // TODO: Add delete logic here
         _birthdayService.Delete(birthdayDelete.Id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #11
0
        public ActionResult Create(BirthdayModel createBirthdayModel)
        {
            try
            {
                // TODO: Add insert logic here

                _birthdayRepository.Add(createBirthdayModel);
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #12
0
        public ActionResult Create(BirthdayModel birthdayCreate)
        {
            try
            {
                // TODO: Add insert logic here
                _birthdayService.Insert(birthdayCreate);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #13
0
        public ActionResult Delete(BirthdayModel birthdayModel)
        {
            try
            {
                // TODO: Add delete logic here

                _birthdayRepository.Remove(birthdayModel.Id);
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public IEnumerable <BirthdayModel> GetAll()
        {
            var sqlQuery = $"SELECT " +
                           $"Id as '{nameof(BirthdayModel.Id)}', " +
                           $"Nome as '{nameof(BirthdayModel.Nome)}', " +
                           $"Sobrenome as '{nameof(BirthdayModel.Sobrenome)}', " +
                           $"DataNascimento as '{nameof(BirthdayModel.DataNascimento)}' " +
                           $"FROM Birthday ORDER BY Id";

            var birthdayList = new List <BirthdayModel>();

            using (var sqlConnection = new SqlConnection(_connectionString))     //já faz o close e dispose
                using (var sqlCommand = new SqlCommand(sqlQuery, sqlConnection)) //já faz o close
                {
                    sqlCommand.CommandType = CommandType.Text;

                    sqlConnection.Open();

                    using (var reader = sqlCommand.ExecuteReader())
                    {
                        var idColumnIndex             = reader.GetOrdinal(nameof(BirthdayModel.Id));
                        var nomeColumnIndex           = reader.GetOrdinal(nameof(BirthdayModel.Nome));
                        var sobrenomeColumnIndex      = reader.GetOrdinal(nameof(BirthdayModel.Sobrenome));
                        var dataNascimentoColumnIndex = reader.GetOrdinal(nameof(BirthdayModel.DataNascimento));
                        while (reader.Read())
                        {
                            var id             = reader.GetFieldValue <int>(idColumnIndex);
                            var nome           = reader.GetFieldValue <string>(nomeColumnIndex);
                            var sobrenome      = reader.GetFieldValue <string>(sobrenomeColumnIndex);
                            var dataNascimento = reader.GetFieldValue <DateTime>(dataNascimentoColumnIndex);

                            var entry = new BirthdayModel
                            {
                                Id             = id,
                                Nome           = nome,
                                Sobrenome      = sobrenome,
                                DataNascimento = dataNascimento
                            };
                            birthdayList.Add(entry);
                        }
                    }
                }

            return(birthdayList);
        }
        public void Initialize()
        {
            if (!Initialized)
            {
                using (var session = Store.OpenSession())
                {
                    var model = session.Load <BirthdayModel>(BirthdayDocumentName);
                    if (model == null)
                    {
                        model = new BirthdayModel();
                        session.Store(model, BirthdayDocumentName);
                        session.SaveChanges();
                    }

                    Model       = model;
                    Initialized = true;
                }
            }
        }
Beispiel #16
0
 public IActionResult Edit(int id, [Bind] BirthdayModel birthdayEdit)
 {
     try
     {
         // TODO: Add update logic here
         if (id != birthdayEdit.Id)
         {
             return(NotFound());
         }
         if (ModelState.IsValid)
         {
             _birthdayService.Update(birthdayEdit);
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(birthdayEdit));
     }
 }
        public void Insert(BirthdayModel birthdayModel)
        {
            var sqlQuery = "INSERT INTO Birthday" +
                           "		(Nome, Sobrenome, DataNascimento)"+
                           "VALUES	(@nome, @sobrenome, @dataNascimento);";

            using (var sqlConnection = new SqlConnection(_connectionString))     //já faz o close e dispose
                using (var sqlCommand = new SqlCommand(sqlQuery, sqlConnection)) //já faz o close
                {
                    sqlCommand.CommandType = CommandType.Text;

                    sqlCommand.Parameters
                    .Add("@nome", SqlDbType.VarChar).Value = birthdayModel.Nome;
                    sqlCommand.Parameters
                    .Add("@sobrenome", SqlDbType.VarChar).Value = birthdayModel.Sobrenome;
                    sqlCommand.Parameters
                    .Add("@dataNascimento", SqlDbType.DateTime).Value = birthdayModel.DataNascimento;
                    sqlConnection.Open();

                    var resutScalar = sqlCommand.ExecuteScalar();
                }
        }
        public void Update(BirthdayModel birthdayModel)
        {
            var sqlQuery = "UPDATE Birthday SET Nome = @nome, Sobrenome = @sobrenome, DataNascimento = @dataNascimento WHERE Id = @id";

            using (var sqlConnection = new SqlConnection(_connectionString))     //já faz o close e dispose
                using (var sqlCommand = new SqlCommand(sqlQuery, sqlConnection)) //já faz o close
                {
                    sqlCommand.CommandType = CommandType.Text;

                    sqlCommand.Parameters
                    .Add("@nome", SqlDbType.VarChar).Value = birthdayModel.Nome;
                    sqlCommand.Parameters
                    .Add("@sobrenome", SqlDbType.VarChar).Value = birthdayModel.Sobrenome;
                    sqlCommand.Parameters
                    .Add("@dataNascimento", SqlDbType.DateTime).Value = birthdayModel.DataNascimento;
                    sqlCommand.Parameters
                    .Add("@id", SqlDbType.Int).Value = birthdayModel.Id;

                    sqlConnection.Open();

                    sqlCommand.ExecuteNonQuery();
                }
        }
        private async Task SaveBirthday()
        {
            if (_model == null)
            {
                _model = new BirthdayModel();
            }

            // We need to find latest leap year in order to have possibility to
            // pick 29 of Feb as someone's Birthday
            const int latestLeapYear = 2020;
            var       dateTime       = new DateTime(
                latestLeapYear,
                SelectedBirthDateViewModel.MonthNumber,
                SelectedBirthDateViewModel.SelectedDay.Number);

            _model.Name            = Name;
            _model.GiftDescription = AdditionalInfo;
            _model.ImageContent    = ImageContent;
            _model.BirthDayDate    = dateTime;
            _model.UserId          = Settings.CurrentUserId;

            App.BirthdaysRepository?.Value.Save(_model);
            await NavigationService.NavigateBackAsync();
        }
Beispiel #20
0
 public void SaveUser(BirthdayModel config)
 {
     Database.Store(config, BirthdayModel.DocumentName(config.UserId));
 }
Beispiel #21
0
        public BirthdayModel GetUser(ulong userId)
        {
            var config = Database.Load <BirthdayModel>(BirthdayModel.DocumentName(userId));

            return(config);
        }
Beispiel #22
0
        // GET: Birthday/Delete/5
        public IActionResult Delete(int id)
        {
            BirthdayModel birthdayDelete = _birthdayService.GetById(id);

            return(View(birthdayDelete));
        }
Beispiel #23
0
        // GET: Birthday/Details/5
        public ActionResult Details(int id)
        {
            BirthdayModel birthdayDetails = _birthdayService.GetById(id);

            return(View(birthdayDetails));
        }
Beispiel #24
0
        public void Update(BirthdayModel editBirthdayModel)
        {
            var oldBirthDayModel = GetById(editBirthdayModel.Id);

            oldBirthDayModel.Nome = editBirthdayModel.Nome;
        }
 public void Update(BirthdayModel birthdayModel)
 {
     _birthdayDB.Update(birthdayModel);
 }
 public void Post([FromBody] BirthdayModel birthDay)
 {
     birthDay.Id = 0;
     _myService.CreateMyEntity(BirthdaysMapper.MapToBirthday(birthDay));
 }
Beispiel #27
0
        // GET: Birthday/Edit/5
        public ActionResult Edit(int id)
        {
            BirthdayModel birthdayEdit = _birthdayService.GetById(id);

            return(View(birthdayEdit));
        }
Beispiel #28
0
 public int DeleteBirthday(BirthdayModel model)
 {
     return(_db.Delete(model));
 }
Beispiel #29
0
 public void Add(BirthdayModel createBirthdayModel)
 {
     Birthdays.Add(createBirthdayModel);
 }