예제 #1
0
        public async Task <IActionResult> EditAge(int id, User user)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }
            User newuser = await db.Users.FirstOrDefaultAsync(c => c.UserId == id);

            newuser.Age = user.Age;
            db.Update(newuser);
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", "Profile", new { id = id }));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Date,Text,User,UserCountry")] Comment comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(comment));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("DescId,Description")] Descriptions descriptions)
        {
            if (id != descriptions.DescId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(descriptions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DescriptionsExists(descriptions.DescId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(descriptions));
        }
예제 #4
0
        public async Task <ActionResult <Bicycle> > PutBicycle(int id, [FromBody] Bicycle bicycle)
        {
            if (bicycle == null)
            {
                return(BadRequest());
            }

            if (id != bicycle.id)
            {
                return(NotFound());
            }

            db.Update(bicycle);
            await db.SaveChangesAsync();

            return(Ok(bicycle));
        }
예제 #5
0
        public async Task <IActionResult> Edit(ApiaryViewModel apiaryViewModel)
        {
            ViewBag.Title = "Редактирование пасеки";


            if (ModelState.IsValid)
            {
                IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);

                Apiary apiar = api.FirstOrDefault(i => i.Name == apiaryViewModel.Name);


                if (apiar == null)
                {
                    string map = apiaryViewModel.Map;
                    if (map != null)
                    {
                        map = apiaryViewModel.Map;
                        int found = apiaryViewModel.Map.IndexOf('"');
                        if (found != -1)
                        {
                            map   = apiaryViewModel.Map.Substring(found);
                            found = map.IndexOf('"');
                            if (found != -1)
                            {
                                map = map.Remove(found);
                            }
                        }
                    }

                    apiar      = _apiary.Apiaries.FirstOrDefault(i => i.Id == apiaryViewModel.Id);
                    apiar.Name = apiaryViewModel.Name;
                    apiar.Map  = map;
                    apiar.Desc = apiaryViewModel.Desc;
                    db.Update(apiar);
                    //await TryUpdateModelAsync<Apiary>(apiar, "", c => c.Name, c => c.Map, c => c.Desc);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("", "Apiary"));
                }
                else
                {
                    apiar = _apiary.Apiaries.FirstOrDefault(i => i.Id == apiaryViewModel.Id);
                    if (apiar.Name == apiaryViewModel.Name)
                    {
                        string map = apiaryViewModel.Map;
                        if (map != null)
                        {
                            int found = apiaryViewModel.Map.IndexOf('"') + 1;
                            if (found != 0)
                            {
                                map   = apiaryViewModel.Map.Substring(found);
                                found = map.IndexOf('"');
                                if (found != -1)
                                {
                                    map = map.Remove(found);
                                }
                            }
                        }


                        apiar.Name = apiaryViewModel.Name;

                        apiar.Map  = map;
                        apiar.Desc = apiaryViewModel.Desc;
                        db.Update(apiar);
                        //await TryUpdateModelAsync<Apiary>(apiar, "", c => c.Name, c => c.Map, c => c.Desc);
                        await db.SaveChangesAsync();

                        return(RedirectToAction("", "Apiary"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Данное Название уже используется");
                        return(View(apiaryViewModel));
                    }
                }
            }
            else
            {
                return(View(apiaryViewModel));
            }
        }
예제 #6
0
 public void SetAge(User user, int age)
 {
     appDBContent.Update(user.Age);
 }