public async Task <IActionResult> Create(PuckWorkflowItem model)
        {
            var success                = false;
            var message                = "";
            PuckWorkflowItem wfi       = null;
            bool             lockTaken = false;

            try
            {
                if (model != null)
                {
                    model.AddedBy = User.Identity.Name;
                }
                if (ModelState.ContainsKey("AddedBy"))
                {
                    ModelState["AddedBy"].Errors.Clear();
                    ModelState["AddedBy"].ValidationState = Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Valid;
                }
                if (!ModelState.IsValid)
                {
                    message = string.Join(",", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                    return(Json(new { success = success, message = message }));
                }
                //await slock1.WaitAsync();
                lockTaken = true;

                var existingItems = repo.GetPuckWorkflowItem().Where(x => x.ContentId == model.ContentId && x.Variant == model.Variant && !x.Complete).ToList();
                existingItems.ForEach(x => { x.Complete = true; x.CompleteDate = DateTime.Now; });

                repo.AddPuckWorkflowItem(model);
                repo.SaveChanges();

                wfi = model;

                success = true;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                log.Log(ex);
            }
            finally {
                //if(lockTaken)
                //    slock1.Release();
            }

            return(Json(new { success = success, message = message, workflowItem = wfi }));
        }
Exemple #2
0
 public void DeletePuckWorkflowItem(PuckWorkflowItem wfi)
 {
     repo.PuckWorkflowItem.Remove(wfi);
 }
Exemple #3
0
 public void AddPuckWorkflowItem(PuckWorkflowItem wfi)
 {
     repo.PuckWorkflowItem.Add(wfi);
 }