Exemple #1
0
        public async Task <bool> UpdateProject(int id, UpdateProjectsOptions options)
        {
            var updproject = await context_.Set <Project>()
                             .SingleOrDefaultAsync(p => p.id == id);

            if (updproject == null)
            {
                return(false);
            }

            if (updproject.Description != null)
            {
                updproject.Description = options.Description;
            }

            if (updproject.budget > 0)
            {
                updproject.budget = options.Budget;
            }

            if (updproject.Tittle != null)
            {
                updproject.Tittle = options.ProjectTitle;
            }

            if (updproject.Photos != null)
            {
                updproject.Photos = options.Photo;
            }

            if (updproject.Videos != null)
            {
                updproject.Videos = options.Video;
            }

            if (updproject.Percentage == 0)
            {
                updproject.IsAvaliable = false;
            }
            else
            {
                updproject.IsAvaliable = true;
            }


            context_.Update(updproject);
            try {
                await context_.SaveChangesAsync();
            } catch (Exception ex) {
                return(false);
            }
            return(true);
        }
        public async Task <bool> UpdateProjectCreator(int id, UpdateCreator options)
        {
            var creator = SearchCreatorById(id);

            if ((id <= 0) ||
                (options == null) ||
                (creator == null) ||
                (options.TotalCost <= 0.0M))
            {
                return(false);
            }
            if (!string.IsNullOrWhiteSpace(options.FirstName))
            {
                creator.FirstName = options.FirstName;
            }
            if (!string.IsNullOrWhiteSpace(options.LastName))
            {
                creator.LastName = options.LastName;
            }
            if (!string.IsNullOrWhiteSpace(options.Password))
            {
                creator.Password = options.Password;
            }
            if (creator == null)
            {
                //elegxo gia ton creator
            }

            var UpdProjectCreator = context_.Set <Creator>().SingleOrDefault(p => p.Id == id);

            if (UpdProjectCreator == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(UpdProjectCreator.FirstName))
            {
                UpdProjectCreator.FirstName = options.FirstName;
            }

            if (!string.IsNullOrEmpty(UpdProjectCreator.LastName))
            {
                UpdProjectCreator.LastName = options.LastName;
            }

            if (!string.IsNullOrEmpty(UpdProjectCreator.Email))
            {
                UpdProjectCreator.Email = options.Email;
            }

            if (UpdProjectCreator.TotalCost > 0)
            {
                UpdProjectCreator.TotalCost = options.TotalCost;
            }
            context_.Update(UpdProjectCreator);
            try {
                context_.SaveChanges();
                Console.WriteLine("Update creator ok");
            } catch (Exception ex) {
                Console.WriteLine("UPDATE CREATOR FAIL" + ex);
                return(false);
            }
            return(true);
        }