Exemplo n.º 1
0
        public AppResult UpdateNotice(Guid ParamId, Notice edit_object)
        {
            var result = new AppResult();

            try
            {
                var response = db.Notices.FirstOrDefault(x => x.IdNotice == ParamId);

                if (response != null)
                {
                    response.Title           = edit_object.Title;
                    response.Content         = edit_object.Content;
                    response.FullDescription = edit_object.FullDescription;
                    response.Img             = edit_object.Img;
                    response.IdCategory      = edit_object.IdCategory;

                    db.SaveChanges();
                }
                string msg = "Noticia Actualizada com sucesso";
                return(result.Good(msg, response));
            }
            catch (Exception e)
            {
                return(result.Bad("Erro ao procesar operação, tente novamente. " + e));
            }
        }
Exemplo n.º 2
0
        public AppResult CreateNotice(Notice new_object)
        {
            var result = new AppResult();

            try
            {
                Notice _notice = new Notice
                {
                    IdNotice        = Guid.NewGuid(),
                    Title           = new_object.Title,
                    Content         = new_object.Content,
                    FullDescription = new_object.FullDescription,
                    Img             = new_object.Img,
                    Status          = true,
                    Created_at      = DateTime.Now,
                    IdCategory      = new_object.IdCategory,
                };
                var response = db.Notices.Add(_notice);
                db.SaveChanges();
                string msg = "Noticia publicada com sucesso";
                return(result.Good(msg, _notice));
            }
            catch (Exception e)
            {
                result.Bad(e.Message);
                return(result.Bad("Erro ao procesar operação, tente novamente."));
            }
        }
Exemplo n.º 3
0
        public AppResult GetCategory(Guid ParamId)
        {
            var res = new AppResult();

            try
            {
                var resposne = db.Categories.Include(x => x.Notices).FirstOrDefault(x => x.IdCategory == ParamId);
                return(res.Good(resposne));
            }
            catch (Exception e)
            {
                return(res.Bad("Erro ao procesar operação, tente novamente. " + e));
            }
        }
Exemplo n.º 4
0
        public AppResult GetCategories()
        {
            var result = new AppResult();

            try
            {
                var response = db.Categories.Include(x => x.Notices).ToList();
                return(result.Good(response));
            }
            catch (Exception e)
            {
                result.Bad(e.Message);
                return(result.Bad("Erro ao procesar operação, tente novamente."));
            }
        }
Exemplo n.º 5
0
        public AppResult GetNotices()
        {
            var result = new AppResult();

            try
            {
                var response = db.Notices.Include(x => x.Category).ToList().OrderByDescending(d => Convert.ToDateTime(d.Created_at));
                return(result.Good(response));
            }
            catch (Exception e)
            {
                result.Bad(e.Message);
                return(result.Bad("Erro ao procesar operação, tente novamente."));
            }
        }
Exemplo n.º 6
0
        public AppResult DeleteCategory(Guid ParamId)
        {
            var result = new AppResult();

            try
            {
                var response = db.Categories.FirstOrDefault(x => x.IdCategory == ParamId);
                if (response != null)
                {
                    db.Categories.Remove(response);
                    db.SaveChanges();
                }
                var msg = "Categoria removida com sucesso";
                return(result.Good(msg));
            }
            catch (Exception e)
            {
                return(result.Bad("Erro ao procesar operação, tente novamente. " + e));
            }
        }
Exemplo n.º 7
0
        public AppResult UpdateCategory(Guid ParamId, Category edit_object)
        {
            var result = new AppResult();

            try
            {
                var response = db.Categories.FirstOrDefault(x => x.IdCategory == ParamId);
                if (response != null)
                {
                    response.Name        = edit_object.Name;
                    response.Description = edit_object.Description;
                    response.Color       = edit_object.Color;
                    db.SaveChanges();
                }
                string msg = "Categoria Actualizada com sucesso";
                return(result.Good(msg, response));
            }
            catch (Exception e)
            {
                return(result.Bad("Erro ao procesar operação, tente novamente. " + e));
            }
        }
Exemplo n.º 8
0
        public AppResult ValidateUser(string username, string password)
        {
            var res = new AppResult();

            try
            {
                var user = db.User.FirstOrDefault(x => x.UserName == username);
                if (user == null)
                {
                    return(res.Bad("There is no user"));
                }

                if (user.Password == password)
                {
                    return(res.Good(user));
                }

                return(res);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 9
0
        public AppResult CreateCategory(Category new_object)
        {
            var result = new AppResult();

            try
            {
                Category _category = new Category
                {
                    IdCategory  = Guid.NewGuid(),
                    Name        = new_object.Name,
                    Description = new_object.Description,
                    Color       = new_object.Color,
                };
                var response = db.Categories.Add(_category);
                db.SaveChanges();
                string msg = "Categoria cadastrada com sucesso";
                return(result.Good(msg, _category));
            }
            catch (Exception e)
            {
                result.Bad(e.Message);
                return(result.Bad("Erro ao procesar operação, tente novamente."));
            }
        }