Beispiel #1
0
        public string Save(string uid, string formname, string displayname)
        {
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            // without the formname and displayname, it cannot be saved.
            if (string.IsNullOrEmpty(formname)
                || string.IsNullOrEmpty(displayname))
            {
                // do nothing.
                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NameOrDisplayNameNotSpecified"));
            }
            else
            {

                try
                {
                    // convert the uid to GUID. if failed to convert, assume that this is a new form.
                    Guid uuid;
                    if (Guid.TryParse(uid, out uuid))
                    {
                        Form form;
                        if (FormsPlugin.Instance.TryRead(formname, out form))
                        {
                            // match the uid
                            if (uuid == form.UId)
                            {
                                logger.Log(LogLevel.Info, "Updating form - {0}, uid - {1}", formname, uuid);
                                form.DisplayName = displayname;

                                FormsPlugin.Instance.Add(form);
                                output.AddOutput("uid", form.UId);
                                output.Success = true;
                            }
                            else
                            {
                                logger.Log(LogLevel.Warn, "Unble to save form with name - [{0}] and uid - {1}. Uid and name mismatch", formname, uuid);

                                // mismatch of name and uid
                                output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NameAndUIdMismatch"));
                            }
                        }
                        else
                        {
                            // unable to locate form with the given name
                            logger.Log(LogLevel.Warn, "Unble to locate form with name - [{0}] and uid - {1}", formname, uuid);
                            output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.NoFormFoundWithName"));
                        }
                    }
                    else
                    {
                        logger.Log(LogLevel.Info, "Creating new form - {0}, display name - [{1}]", formname, displayname);

                        Form form = new Form();
                        try
                        {
                            form.Name = formname;
                        }
                        catch (ArgumentException)
                        {
                            throw new MessageException(ResourceManager.GetLiteral("Admin.Forms.Save.Error.FormNameInvalid"));
                        }

                        form.DisplayName = displayname;

                        FormsPlugin.Instance.Add(form);

                        output.AddOutput("uid", form.UId);
                        output.Success = true;
                    }
                }
                catch (MessageException me)
                {
                    logger.Log(LogLevel.Warn, "Unble to save form - {0} ", me);

                    if (me.ErrorNumber == PluginErrorCodes.IdAlreadyInUse)
                    {
                        output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Forms.Save.Error.FormNameInUse"));
                    }
                    else
                    {
                        output.AddOutput(Constants.Json.Error, me.Message);
                    }

                    output.Success = false;
                }
            }

            return output.GetJson();
        }
Beispiel #2
0
        public void Add(Form form)
        {
            #region argument checking

            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            if (!form.IsValid())
            {
                throw new InvalidOperationException("form is invalid");
            }

            #endregion

            try
            {
                // add the form
                PluginStore.Instance.Save(this, form);
            }
            catch (MessageException me)
            {
                if (me.ErrorNumber == PluginErrorCodes.IdAlreadyInUse)
                {
                    // throw with a new message
                    throw new MessageException(me.ErrorNumber, ResourceManager.GetMessage(FormMessages.NameAlreadyInUse));
                }

                throw;
            }
        }
Beispiel #3
0
        private void RenderFormHead(Form form)
        {
            IList<Field> fields = form.Fields;
            if (fields != null && fields.Count > 0)
            {
                int count = 0;

                foreach (Field field in fields)
                {

                    if (count >= displayColumnsCount)
                    {
                        break;
                    }

                    HtmlTableCell cell = new HtmlTableCell("th");
                    cell.InnerText = field.Name;
                    headtr.Cells.Add(cell);

                    count++;
                }

            }
        }
Beispiel #4
0
        public bool TryRead(string name, out Form form)
        {
            form = null;
            bool success = false;

            try
            {
                form = PluginStore.Instance.Read<Form>(this, Form.KeyName, name);
                success = true;
            }
            catch (MessageException me)
            {
                if (me.ErrorNumber != PluginErrorCodes.PluginDataNotFound)
                {
                    throw;
                }
            }

            return success;
        }