Exemple #1
0
        public async Task <IHttpActionResult> CopyDefaultSteps(int planId, int departmentPlanId)
        {
            if (!DepartmentPlanExists(departmentPlanId))
            {
                //Copy default steps to steps and associate with department planId
                var stepCopy = await db.DefaultSteps.Where(s => s.PlanID == planId).ToListAsync();

                foreach (var data in stepCopy)
                {
                    Step step = new Step
                    {
                        DepartmentPlanID = departmentPlanId,
                        Number           = data.Number,
                        Title            = data.Title,
                        Summary          = data.Summary,
                        Detail           = data.Detail
                    };

                    db.Steps.Add(step);
                }

                await db.SaveChangesAsync();
            }

            //Get steps
            var steps = await GetStepsByPlanId(departmentPlanId);

            return(Ok(steps));
        }
        public async Task <IHttpActionResult> AddEditThirdParty(ThirdParty thirdParty)
        {
            string status = "";

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Edit or add depending on if id exists
            if (!ThirdPartyExists(thirdParty.ThirdPartyID))
            {
                db.ThirdParties.Add(thirdParty);
                await db.SaveChangesAsync();

                status = "created";
            }
            else
            {
                db.Entry(thirdParty).State = EntityState.Modified;

                //When value is not specified for model DateTime property, the value defaults to 0001-01-01
                //which is outside of the range of SQL Server's DATETIME
                thirdParty.DateModified = DateTime.Now;

                try
                {
                    await db.SaveChangesAsync();

                    status = "updated";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ThirdPartyExists(thirdParty.ThirdPartyID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            string message = $"ThirdParty successfully { status }!";

            return(Ok(new PostResponseViewModel {
                Ids = new List <int>()
                {
                    thirdParty.ThirdPartyID
                }, Message = message
            }));
        }
Exemple #3
0
        public async Task <IHttpActionResult> AssignPlanOwner(string userId, int departmentPlanId)
        {
            string message = "";

            //When value is not specified for model DateTime property, the value defaults to 0001-01-01
            //which is outside of the range of SQL Server's DATETIME
            //plan.DateModified = DateTime.Now;

            //Get department plan
            var departmentPlan = await db.DepartmentPlans.FindAsync(departmentPlanId);

            //Get user
            var user = db.Users.Find(userId);

            //Attach user
            departmentPlan.Users.Add(user);

            //Save changes
            await db.SaveChangesAsync();

            message = "Plan owner assigned";


            return(Ok(new PostResponseViewModel {
                Ids = new List <int>()
                {
                    departmentPlan.DepartmentPlanID
                }, Message = message
            }));
        }
        public async Task <IHttpActionResult> AddEditPlan(Plan plan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Edit or add depending on if id exists
            if (!PlanExists(plan.PlanID))
            {
                db.Plans.Add(plan);

                await db.SaveChangesAsync();
            }

            return(Ok(new PostResponseViewModel {
                Ids = new List <int>()
                {
                    plan.PlanID
                }, Message = null
            }));
        }