public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Department department)
        {
            if (id != department.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ContactNumber")] Department department)
        {
            department.LastUpdated = DateTime.Now;
            if (id != department.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();

                    Message message = new Message()
                    {
                        DepartmentId   = department.Id.ToString(),
                        DepartmentName = department.Name
                    };

                    try
                    {
                        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, $"api/DepartmentContact")
                        {
                            Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new List <Message>()
                            {
                                message
                            }), Encoding.UTF8, "application/json")
                        };
                        HttpClient          client   = _clientFactory.CreateClient("portal");
                        HttpResponseMessage response = await client.SendAsync(request);
                    } catch (Exception)
                    {
                        //Log
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
示例#3
0
 public IActionResult Put([FromBody] Employee employee)
 {
     if (ModelState.IsValid)
     {
         if (db.Employees.Where(e => e.Email == employee.Email).Count() == 0)
         {
             db.Update(employee);
             db.SaveChanges();
             return(Ok(employee));
         }
         {
             return(BadRequest(ModelState));
         }
     }
     return(BadRequest(ModelState));
 }
示例#4
0
 public IActionResult Put(int id, [FromBody] Department department)
 {
     if (ModelState.IsValid)
     {
         if (db.Departments.Where(e => e.Name == department.Name).Count() == 0)
         {
             db.Update(department);
             db.SaveChanges();
             return(Ok(department));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     return(BadRequest(ModelState));
 }