示例#1
0
 public bool Add(RepScheduleDto repSchedule)
 {
     _context.Add(repSchedule);
     _context.SaveChanges();
     return(true);
 }
示例#2
0
 public bool Add(SupplyDto supply)
 {
     _context.Add(supply);
     _context.SaveChanges();
     return(true);
 }
        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
            }));
        }