public async Task <IActionResult> PutUsers([FromRoute] int id, [FromBody] Users users) { try { if (!ModelState.IsValid) { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } if (id != users.UserId) { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound(new { status = false, message = HttpStatusCode.NotFound.ToString() })); } else { throw; } } return(Ok(new { status = true, data = users })); } catch { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } }
public async Task <IActionResult> Create([FromBody] OrderCreateRequest model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var order = _mapper.Map <Order>(model); await _context.Order.AddAsync(order); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetOrderById", new { id = order.OrderId }, order)); }
public async Task <IActionResult> Create([FromBody] DrugCreateRequest model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var drug = _mapper.Map <Drug>(model); await _context.Drug.AddAsync(drug); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetDrugById", new { id = drug.DrugId }, drug)); }
public async System.Threading.Tasks.Task Add(Task task) { _context.Tasks.Add(task); await _context.SaveChangesAsync(); }
public async Task <IActionResult> PutMilestones([FromRoute] int id, [FromBody] Milestones milestones) { if (!ModelState.IsValid) { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } //if (EmptyOrNullValidation.IsAnyNullOrEmpty(milestones)) //{ // //return BadRequest(new // //{ // // status = HttpStatusCode.BadRequest.ToString(), // // message = "Values cannot be empty" // //}); //} if (id != milestones.MilestoneId) { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } //if (MilestonesExistsByNameId(milestones.MilestoneId, milestones.Name)) //{ // return BadRequest(new // { // status = false, // message = "Milestone already exists with name : " + milestones.Name + "." // }); //} Milestones objMilestones = _context.Milestones.Where(x => x.MilestoneId == id).FirstOrDefault(); if (objMilestones != null) { //var _RecievedAmount = objMilestones.RecievedAmount + milestones.RecievedAmount; objMilestones.RecievedAmount += milestones.RecievedAmount; objMilestones.Name = milestones.Name; objMilestones.Notes = milestones.Notes; objMilestones.IsCompleted = milestones.IsCompleted; objMilestones.PaymentReceived = milestones.PaymentReceived; objMilestones.ProjectId = milestones.ProjectId; objMilestones.StartDate = milestones.StartDate; objMilestones.Amount = milestones.Amount; objMilestones.DatePaymentReceived = milestones.DatePaymentReceived; objMilestones.DueDate = milestones.DueDate; objMilestones.EndDate = milestones.EndDate; objMilestones.Description = milestones.Description; } try { await _context.SaveChangesAsync(); //=> To update project estimated cost based on milestone UpdateProjectEstimatedCost(milestones.ProjectId); } catch (DbUpdateConcurrencyException) { if (!MilestonesExists(id)) { return(NotFound(new { status = false, message = HttpStatusCode.NotFound.ToString() })); } else { throw; } } return(Ok(new { status = true, data = milestones })); }
public async Task <IActionResult> PutProjects([FromRoute] int id, [FromBody] Projects projects) { if (!ModelState.IsValid) { return(BadRequest(new { status = false, message = ModelState.Keys })); } if (id != projects.ProjectId) { return(BadRequest(new { status = false, message = HttpStatusCode.BadRequest.ToString() })); } //if (ProjectsExistsByNameId(projects.ProjectId, projects.Name)) //{ // return BadRequest(new // { // status = false, // message = "Project already exists with name : " + projects.Name + "." // }); //} _context.Entry(projects).State = EntityState.Modified; try { await _context.SaveChangesAsync(); Projects objProjects = _context.Projects.Where(e => e.ProjectId == projects.ProjectId).FirstOrDefault(); if (objProjects.Milestones == null) { if (projects.ProjectType.ToLower() == "hourly") { //=> Add milestone Milestones _Milestones = new Milestones(); _Milestones.Name = "Milestone 1 " + projects.Name; _Milestones.Description = "Milestone 1 Description"; _Milestones.Amount = projects.EstimatedCost; _Milestones.RecievedAmount = 0; _Milestones.PaymentReceived = false; _Milestones.StartDate = projects.DateAssigned; _Milestones.DueDate = projects.DateCompleted ?? projects.DateAssigned; _Milestones.EndDate = projects.DateCompleted; _Milestones.IsCompleted = false; //_Milestones.DatePaymentReceived = DateTime.Now; _Milestones.ProjectId = projects.ProjectId; _Milestones.Notes = "This Milestone is added as default. Please update if required."; _context.Add(_Milestones); _context.SaveChanges(); } } else if (objProjects.Milestones.Count == 0) { if (projects.ProjectType.ToLower() == "hourly") { //=> Add milestone Milestones _Milestones = new Milestones(); _Milestones.Name = "Milestone 1 " + projects.Name; _Milestones.Description = "Milestone 1 Description"; _Milestones.Amount = projects.EstimatedCost; _Milestones.RecievedAmount = 0; _Milestones.PaymentReceived = false; _Milestones.StartDate = projects.DateAssigned; _Milestones.DueDate = projects.DateCompleted ?? projects.DateAssigned; _Milestones.EndDate = projects.DateCompleted; _Milestones.IsCompleted = false; //_Milestones.DatePaymentReceived = DateTime.Now; _Milestones.ProjectId = projects.ProjectId; _Milestones.Notes = "This Milestone is added as default. Please update if required."; _context.Add(_Milestones); _context.SaveChanges(); } } } catch (DbUpdateConcurrencyException) { if (!ProjectsExists(id)) { return(NotFound(new { status = false, message = HttpStatusCode.NotFound.ToString() })); } else { throw; } } // return Ok(projects); return(Ok(new { status = true, data = projects })); }