Пример #1
0
        public RQItem Post(string dbname, string id, [FromBody] RQItem changeRQItem)
        {
            if (ModelState.IsValid)
            {
                RQItemModelRepository repo  = new RQItemModelRepository((new FormatParameter(FormatParameter.FormatEnum.rqi)));
                RQItemModel           model = null;
                RQItem rqitem = null;

                model  = repo.GetModel("$access$" + id, UserState.States.EditState, true);
                rqitem = model.RQItems.FirstOrDefault(p => p.DocNo == id);
                rqitem.Change(changeRQItem);
                model.Update();
                CacheManager.Clear();
                return(Get("rqitems", id, "rqi", "edititem", ""));
            }
            else
            {
                throw new HttpResponseException(JsonErrorResponse.InvalidData());
            }
        }
Пример #2
0
        public ActionResult UpdateItem(string verb, string rqitemId, string serviceId, RQItem changeRQItem)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if ((rqitemId != null) && (rqitemId != ""))
            {
                if ((verb.ToLower() == "cancel") || (verb == RQResources.Views.Shared.SharedStrings.cancel))
                {
                    return(this.RedirectToRoute("RQItemList", new { dbname = "rqitems" }));
                }
                else if ((verb.ToLower() == "finalize") || (verb == RQResources.Views.Shared.SharedStrings.finish))
                {
                    return(this.RedirectToRoute("RQItemList", new { dbname = "rqitems" }));
                }
                else
                {
                    if (MvcRQ.Helpers.AccessRightsResolver.HasAddAccess())
                    {
                        RQItemModel model  = null;
                        RQItem      rqitem = null;
                        try
                        {
                            model  = modelRepository.GetModel("$access$" + rqitemId, UserState.States.EditState, true);
                            rqitem = model.RQItems.FirstOrDefault(p => p.DocNo == rqitemId);
                            if ((verb.ToLower() == "update") || (verb == RQResources.Views.Shared.SharedStrings.update))
                            {
                                rqitem.Change(changeRQItem);
                            }
                            else if ((verb.ToLower() == "new") || (verb == RQResources.Views.Shared.SharedStrings.add))
                            {
                                rqitem = model.Add(changeRQItem);
                            }
                            else if ((verb.ToLower() == "delete") || (verb == RQResources.Views.Shared.SharedStrings.delete))
                            {
                            }   // not yet implemented
                            model.Update();
                        }
                        catch (Exception ex)
                        {
                            string    message = "Update operation failed. ";
                            Exception iex     = ex;

                            while (iex != null)
                            {
                                if (!string.IsNullOrEmpty(iex.Message))
                                {
                                    message += "\n - " + iex.Message;
                                }
                                iex = iex.InnerException;
                            }
                            throw new Exception(message);
                        };
                        CacheManager.Clear();
                        ViewBag.EditButton2 = RQResources.Views.Shared.SharedStrings.finish;
                        if (AccessRightsResolver.HasAddAccess())
                        {
                            ViewBag.EditButton3     = RQResources.Views.Shared.SharedStrings.copy;
                            ViewBag.EditButton3Link = "/RQItems/" + rqitem.DocNo + "?verb=copy";
                            ViewBag.EditButton4     = RQResources.Views.Shared.SharedStrings.add;
                            ViewBag.EditButton4Link = "/RQItems?verb=new";
                        }
                        return(RQItemRecord((verb == "") ? verb : "edititem", rqitem.DocNo, serviceId));
                    }
                    else
                    {
                        throw new System.AccessViolationException(RQResources.Views.Shared.SharedStrings.err_not_authorized);
                    }
                }
            }
            throw new NotImplementedException("No item for update specified.");
        }