示例#1
0
        public async Task <Result> Edit(
            int id,
            string location,
            string description,
            string imageUrl,
            string startDate,
            string endDate,
            string categoryName,
            string userId)
        {
            Trek trek = await this.GetByIdAndByUserId(id, userId);

            if (trek == null)
            {
                return("You are not authorized to update this trek!");
            }

            trek.Location    = location;
            trek.Description = description;
            trek.ImageUrl    = imageUrl;
            trek.StartDate   = startDate;
            trek.CategoryId  = this.data.Categories.Where(c => c.Name == categoryName).FirstOrDefault().Id;

            await this.data.SaveChangesAsync();

            return(true);
        }
示例#2
0
        public async Task <int> Create(string location, string description, string imageUrl, string startDate, string endDate, string categoryName, string userId)
        {
            var trek = new Trek
            {
                Location    = location,
                Description = description,
                ImageUrl    = imageUrl,
                StartDate   = startDate,
                EndDate     = endDate,
                CategoryId  = this.data.Categories.Where(c => c.Name == categoryName).FirstOrDefault().Id,
                UserId      = userId,
                Likes       = 0
            };

            this.data.Add(trek);

            await this.data.SaveChangesAsync();

            return(trek.Id);
        }