Esempio n. 1
0
        public bool Create(AwardDTO award)
        {
            int summary;

            using (var connection = new SqlConnection(UsersConnectionString))
            {
                var command = connection.CreateCommand();
                command.CommandText = "INSERT INTO dbo.Awards_Table (Guid, Name, image_id) VALUES(@awardId, @awardName, @awardImage)";
                command.Parameters.AddWithValue("@awardId", award.Id);
                command.Parameters.AddWithValue("@awardName", award.Name);
                command.Parameters.AddWithValue("@awardImage", award.Image);
                connection.Open();
                summary = command.ExecuteNonQuery();
            }
            if (summary > 0)
            {
                return(true);
            }
            else
            {
                DBconnectException e = new DBconnectException("Can't create award-model");
                LogType.AddLog(e);
                return(false);
            }
        }
Esempio n. 2
0
        public IEnumerable <AwardDTO> Load()
        {
            try
            {
                using (StreamReader read = new StreamReader(file.FullName))
                {
                    string   line  = null;
                    AwardDTO award = new AwardDTO();
                    while (true)
                    {
                        line = read.ReadLine();
                        if (line == "Award:")
                        {
                            award.Id    = Guid.Parse(read.ReadLine());
                            award.Title = read.ReadLine();
                            Awards.Add(award);
                            award = new AwardDTO();
                        }

                        else
                        {
                            break;
                        }
                    }
                }
                return(Awards);
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
Esempio n. 3
0
        public async Task <bool> EditAwardAsync(AwardDTO award)
        {
            var path   = Properties.Resources.editAwardPath;
            var result = await _apiHelper.Put(path, award);

            return(result != null && result.ResponseType == ResponseType.Success);
        }
Esempio n. 4
0
        public bool Update(AwardDTO note)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                var add_award = connection.CreateCommand();
                if (note.ImageId == null)
                {
                    add_award.CommandText = $"UPDATE dbo.Award SET AwardId = @AwardId , Title = @Title WHERE AwardId = @AwardId";
                    add_award.Parameters.AddWithValue("@AwardId", note.Id);
                    add_award.Parameters.AddWithValue("@Title", note.Title);
                }

                else
                {
                    add_award.CommandText = $"UPDATE dbo.Award SET AwardId = @AwardId , Title = @Title, ImageId = @ImageId WHERE AwardId = @AwardId";
                    add_award.Parameters.AddWithValue("@AwardId", note.Id);
                    add_award.Parameters.AddWithValue("@Title", note.Title);
                    add_award.Parameters.AddWithValue("@ImageId", note.ImageId);
                }

                connection.Open();
                var result = add_award.ExecuteNonQuery();
                return(result > 0);
            }
        }
Esempio n. 5
0
        public bool Update(AwardDTO award)
        {
            try
            {
                int c = 0;
                foreach (var item in Awards)
                {
                    if (item.Id == award.Id)
                    {
                        Awards[c] = award;
                        return(true);
                    }

                    c++;
                }

                return(true);
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
Esempio n. 6
0
        public void AddAward(AwardDTO awardDTO)
        {
            var award = MapperExtension.mapper.Map <AwardDTO, Award>(awardDTO);

            _db.Awards.Add(award);
            _db.SaveChanges();
        }
Esempio n. 7
0
        public bool Update(AwardDTO award)
        {
            int summary;

            using (var connection = new SqlConnection(UsersConnectionString))
            {
                var command = connection.CreateCommand();
                command.CommandText = "UPDATE dbo.Awards_Table  SET Name = @awardName, image_id = @awardImage WHERE Guid = @awardId; ";
                command.Parameters.AddWithValue("@awardName", award.Name);
                command.Parameters.AddWithValue("@awardImage", award.Image);
                command.Parameters.AddWithValue("@awardId", award.Id);
                connection.Open();
                summary = command.ExecuteNonQuery();
            }
            if (summary > 0)
            {
                return(true);
            }
            else
            {
                DBconnectException e = new DBconnectException("Can't update award-model");
                LogType.AddLog(e);
                return(false);
            }
        }
Esempio n. 8
0
        public void EditAward(AwardDTO awardDTO)
        {
            var award = MapperExtension.mapper.Map <AwardDTO, Award>(awardDTO);

            _db.Entry(_db.Awards.Find(awardDTO.AwardId)).CurrentValues.SetValues(award);
            _db.SaveChanges();
        }
Esempio n. 9
0
 public IHttpActionResult EditAward([FromBody] AwardDTO award)
 {
     if (_bll.EditAward(award))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
Esempio n. 10
0
 public bool Create(AwardDTO user)
 {
     try
     {
         return(DAL.Create(user));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 11
0
 public bool EditAward(AwardDTO award)
 {
     try
     {
         _repository.EditAward(award);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Esempio n. 12
0
 public bool Create(AwardDTO note)
 {
     try
     {
         Awards.Add(note);
         return(true);
     }
     catch (Exception e)
     {
         throw new NullReferenceException("нет записи награждения", e);
     }
 }
Esempio n. 13
0
 public bool Create(AwardDTO award)
 {
     try
     {
         Awards.Add(award);
         return(true);
     }
     catch (Exception e)
     {
         LogType.AddLog(e);
         throw new CacheAccessException("Can't save data to cache!", e);
     }
 }
Esempio n. 14
0
 public bool Create(AwardDTO note)
 {
     try
     {
         Awards.Add(note);
         return(true);
     }
     catch (Exception e)
     {
         Logger.Logger.WriteLog(e);
         throw new NullReferenceException("нет записи награды", e);
     }
 }
Esempio n. 15
0
        public bool Create(AwardDTO note)
        {
            try
            {
                return(dal.Create(note));
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
Esempio n. 16
0
        public bool Update(AwardDTO user)
        {
            try
            {
                dal.Update(user);
                return(true);
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
Esempio n. 17
0
        public int AddAward(AwardDTO award)
        {
            if (award == null || string.IsNullOrWhiteSpace(award.Title) || award.Title.Length > ModelRules.MaxNameLength)
            {
                return(ModelRules.LowerBoundOfId - 1);
            }

            if (string.IsNullOrWhiteSpace(award.Description))
            {
                award.Description = string.Empty;
            }

            award.Id = ModelRules.LowerBoundOfId - 1;

            return(dal.AddAward(award));
        }
Esempio n. 18
0
        public int AddAward(AwardDTO award)
        {
            using (SqlConnection connection = new SqlConnection(config.ConnectionString))
            {
                SqlCommand command = helper.IntializeCommand(
                    "[dbo].[Award.AddAward]",
                    connection,
                    new string[] { "@Title", "@Description", "@ImageId" },
                    new object[] { award.Title, award.Description, award.ImageId }
                    );

                connection.Open();
                int id = (int)(decimal)command.ExecuteScalar();

                return(id);
            }
        }
Esempio n. 19
0
        public bool UpdateAward(AwardDTO updatedAward)
        {
            using (SqlConnection connection = new SqlConnection(config.ConnectionString))
            {
                SqlCommand command = helper.IntializeCommand(
                    "[dbo].[Award.UpdateAward]",
                    connection,
                    new string[] { "@Id", "@Title", "@Description", "@ImageId" },
                    new object[] { updatedAward.Id, updatedAward.Title, updatedAward.Description, updatedAward.ImageId }
                    );

                connection.Open();
                int countRow = command.ExecuteNonQuery();

                return(countRow > 0);
            }
        }
Esempio n. 20
0
 public bool Update(AwardDTO award)
 {
     try
     {
         var temp = Awards.FirstOrDefault(x => x.Id == award.Id);
         if (temp == null)
         {
             return(false);
         }
         temp.Name = award.Name;
         return(true);
     }
     catch (Exception e)
     {
         LogType.AddLog(e);
         throw new CacheAccessException("Can't access to cache!", e);
     }
 }
        public static Award DTOToAward(AwardDTO awardDTO)
        {
            DateTime?inputDate = awardDTO.DateReceived;

            if (awardDTO.DateReceived.HasValue)
            {
                inputDate = awardDTO.DateReceived.GetValueOrDefault();
            }
            return(new Award
            {
                ResumeId = awardDTO.ResumeId,
                Order = awardDTO.Order,
                Name = awardDTO.Name,
                DateReceived = inputDate,
                Value = awardDTO.value,
                Resume = null
            });
        }
Esempio n. 22
0
        public bool UpdateAward(AwardDTO updatedAward)
        {
            if (updatedAward == null || string.IsNullOrWhiteSpace(updatedAward.Title))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(updatedAward.Description))
            {
                updatedAward.Description = string.Empty;
            }

            if (updatedAward.Description.Length > ModelRules.MaxDescriptionLength)
            {
                return(false);
            }

            return(dal.UpdateAward(updatedAward));
        }
Esempio n. 23
0
        public IEnumerable <AwardDTO> GetAll()
        {
            using (var connection = new SqlConnection(UsersConnectionString))
            {
                var             fcommand = connection.CreateCommand();
                var             scommand = connection.CreateCommand();
                List <AwardDTO> Awards   = new List <AwardDTO>();
                fcommand.CommandText = "SELECT Guid, Name, image_id FROM dbo.Awards_Table";
                connection.Open();
                AwardDTO award = null;
                Guid     guid;
                string   name;
                int      image;
                DateTime sdate;
                using (SqlDataReader reader = fcommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        guid  = (Guid)reader["Guid"];
                        name  = (string)reader["Name"];
                        image = (int)reader["image_id"];
                        award = new AwardDTO(name, guid, image);
                        scommand.CommandText = "SELECT [Guid], [Name], [image_id], [Date] FROM dbo.Users_Table u, dbo.UsersAwards a WHERE a.user_id = u.Guid AND a.award_id=@guid";
                        scommand.Parameters.AddWithValue("@guid", guid);
                        using (SqlDataReader new_reader = scommand.ExecuteReader())
                        {
                            while (new_reader.Read())
                            {
                                guid  = (Guid)new_reader["Guid"];
                                name  = (string)new_reader["Name"];
                                image = (int)new_reader["image_id"];
                                sdate = (DateTime)new_reader["Date"];
                                award.Users.Add(new UserDTO(name, sdate, guid, image));
                            }
                        }
                        Awards.Add(award);
                        scommand.Parameters.Clear();
                    }
                }

                return(Awards);
            }
        }
        public async Task <ActionResult <AwardDTO> > PostAward(AwardDTO awardDTO)
        {
            Award sanitizedAward = DTOToAward(awardDTO);

            if (!await ResumeAccessAuthorized(sanitizedAward.ResumeId))
            {
                return(GenerateResumeNotFoundError(sanitizedAward.ResumeId));
            }

            if (AwardExists(sanitizedAward.ResumeId, sanitizedAward.Order))
            {
                return(BadRequest("associated subsection already exists"));
            }

            _context.Awards.Add(sanitizedAward);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostAward", new { resumeId = sanitizedAward.ResumeId, order = sanitizedAward.Order }, awardDTO));
        }
        public async Task <IActionResult> PatchAward(long resumeId, long order, AwardDTO awardDTO)
        {
            Award sanitizedAward = DTOToAward(awardDTO);

            if (resumeId != sanitizedAward.ResumeId)
            {
                return(BadRequest("resumeId in query params does not match resumeId in body"));
            }

            if (order != sanitizedAward.Order)
            {
                return(BadRequest("subsection order in query params does not match subsection order in body"));
            }

            User user = await userManager.FindByNameAsync(User.Identity.Name);

            IList <string> roles = await userManager.GetRolesAsync(user);

            if (!await ResumeAccessAuthorized(sanitizedAward.ResumeId))
            {
                return(GenerateResumeNotFoundError(sanitizedAward.ResumeId));
            }

            if (!AwardExists(resumeId, order))
            {
                return(BadRequest("Associated subsection does not exist"));
            }
            _context.Entry(sanitizedAward).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(AcceptedAtAction("PatchAward", new { resumeId = sanitizedAward.ResumeId, order = sanitizedAward.Order }, awardDTO));
        }
Esempio n. 26
0
        private async void PresentationList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SessionList.SelectedValue != null)
            {
                AwardDTO award = null;
                if (SessionComboBox.SelectedIndex != 0)
                {
                    award = await core.GetAwardForSessionAsync(null, (int)SessionList.SelectedValue);
                }
                else
                {
                    award = await core.GetAwardForSessionAsync((int)SessionList.SelectedValue, null);
                }

                if (award != null)
                {
                    if (PresentationList.SelectedIndex < 0)
                    {
                        await core.DeleteAwardAsync(award.AwardId);
                    }
                    else if ((int)PresentationList.SelectedValue != award.PresentationId)
                    {
                        award.PresentationId = (int)PresentationList.SelectedValue;
                        await core.EditAwardAsync(award);
                    }
                }
                else
                {
                    if (PresentationList.SelectedIndex >= 0)
                    {
                        await core.AddAwardAsync(new AwardDTO()
                        {
                            Date           = DateTime.Now,
                            PresentationId = (int)PresentationList.SelectedValue
                        });
                    }
                }
            }
        }
Esempio n. 27
0
        public bool Create(AwardDTO note)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                var add_award = connection.CreateCommand();
                if (note.ImageId == null)
                {
                    add_award.CommandText = $"INSERT INTO dbo.Award (AwardId, Title) VALUES (@AwardId, @Title)";
                    add_award.Parameters.AddWithValue("@AwardId", note.Id);
                    add_award.Parameters.AddWithValue("@Title", note.Title);
                }

                else
                {
                    add_award.CommandText = $"INSERT INTO dbo.Award (AwardId, Title, ImageId) VALUES (@AwardId, @Title, @ImageId)";
                    add_award.Parameters.AddWithValue("@AwardId", note.Id);
                    add_award.Parameters.AddWithValue("@Title", note.Title);
                    add_award.Parameters.AddWithValue("@ImageId", note.ImageId);
                }
                connection.Open();
                var result = add_award.ExecuteNonQuery();
                return(result > 0);
            }
        }
Esempio n. 28
0
 static void PrintAwardConsole(AwardDTO award)
 {
     System.Console.Write(" {0}", award.Title);
 }
Esempio n. 29
0
 public bool UpdateAward(AwardDTO award)
 {
     return(awardBll.UpdateAward(award));
 }
Esempio n. 30
0
 public int AddAward(AwardDTO awardDTO)
 {
     return(awardBll.AddAward(awardDTO));
 }