public HttpResponseMessage DeleteChecklistAction(int id)
        {
            checklist_action_ref data = db.CheckListActions.Find(id);

            if (data == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.CheckListActions.Remove(data);

            var chklistactionitems = db.CheckListActionsXref.Where(s => s.checklist_action_id == id);

            db.CheckListActionsXref.RemoveRange(chklistactionitems);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, data));
        }
        public HttpResponseMessage PutChecklistAction(int id, checklist_action_ref data)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != data.checklist_action_id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(data).State = System.Data.Entity.EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public checklist_action_ref GetChecklistAction(int id)
        {
            if (id == 0)
            {
                return(GetEmptyChecklistAction());         //Used to create empty structure for configuration_ref for ADD-NEW-Record
            }
            checklist_action_ref item = db.CheckListActions.Find(id);

            if (item == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(item);
        }
        public HttpResponseMessage PostChecklistAction(checklist_action_ref data)
        {
            if (ModelState.IsValid)
            {
                // Get sub type ID from template
                checklist_template_ref tmprefdata = db.CheckListTemplates.Find(data.checklist_template_id);

                if (tmprefdata != null)
                {
                    data.sub_type_id = tmprefdata.sub_type_id;
                }

                db.CheckListActions.Add(data);
                db.SaveChanges();

                //For start new checklist : Add all checklist items from template : This will happen only first time when new checklist-action is added

                var itemsToBeAddedfromTemplate = (from chktempxref in db.CheckListTemplatesXref
                                                  where chktempxref.checklist_template_id == data.checklist_template_id
                                                  select chktempxref).ToList();

                List <checklist_action_xref> addchecklistActionItems = new List <checklist_action_xref>();
                foreach (var item in itemsToBeAddedfromTemplate)
                {
                    checklist_action_xref row = new checklist_action_xref();
                    row.checklist_action_id        = data.checklist_action_id;
                    row.checklist_id               = item.checklist_id;
                    row.priority_order             = item.priority_order;
                    row.status_id                  = (short)CheckListStatus.NOTSTARTED;
                    row.powershell_script          = item.powershell_script;
                    row.powershell_script_timedout = item.powershell_script_timedout;
                    addchecklistActionItems.Add(row);
                }
                db.CheckListActionsXref.AddRange(addchecklistActionItems);
                db.SaveChanges();
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, data);
                //response.Headers.Location = new Uri(Url.Link("ApiByName", new { id = configuration.config_id }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }