Example #1
0
        private static object DataProcess(Models.Vendor data, string userName)
        {
            try
            {
                return(new
                {
                    Id = data.Id,
                    Title = data.Title,
                    Logo = data.Logo,
                    HomePage = data.HomePage,
                    Phone = data.Phone,
                    Phone_400 = data.Phone_400,
                    Phone_800 = data.Phone_800,
                    Fax = data.Fax,
                    Email = data.Email,
                    Address = data.Address,
                    PostNo = data.PostNo,
                    Description = data.Description,
                    Creator = RestfulJsonProccessor.Account.MiniSingle(data.Creator),
                    Created = data.Created.ToString(),
                    Updated = data.Updated.ToString(),

                    Options = ControlProcess(data, userName)
                });
            }
            catch
            {
                throw;
            }
        }
Example #2
0
 public static object MiniSingle(Models.Vendor data)
 {
     try
     {
         return(new
         {
             Id = data.Id,
             Title = data.Title,
             Logo = data.Logo
         });
     }
     catch
     {
         return(null);
     }
 }
Example #3
0
        public static IList <RestfulJsonProccessor.RestfulOption> ControlProcess(Models.Vendor data, string userName)
        {
            try
            {
                if ((new Models.AccountMembershipService()).IsAdmin(userName))
                {
                    var options = new List <RestfulJsonProccessor.RestfulOption>();

                    options.Add(
                        new RestfulJsonProccessor.RestfulOption()
                    {
                        Object           = "Vendor",
                        ObjectId         = data.Id,
                        ActionId         = "Edit_Vendor",
                        ActionName       = "修改",
                        ActionDefinition = "修改供应商信息",
                        ActionType       = Models.RestfulAction.Update,
                        HttpMethod       = "PUT",
                        Uri = Models.ApplicationConfig.Domain + "Api/Vendor/" + data.Id
                    }
                        );

                    options.Add(
                        new RestfulJsonProccessor.RestfulOption()
                    {
                        Object           = "Vendor",
                        ObjectId         = data.Id,
                        ActionId         = "Delete_Vendor",
                        ActionName       = "删除",
                        ActionDefinition = "删除供应商信息",
                        ActionType       = Models.RestfulAction.Delete,
                        HttpMethod       = "DELETE",
                        Uri = Models.ApplicationConfig.Domain + "Api/Vendor/" + data.Id
                    }
                        );

                    return(options);
                }
                else
                {
                    return(null);
                }
            }
            catch {
                return(null);
            }
        }
        public object Post(Models.Vendor added)
        {
            object json;
            string messageError = "";

            try
            {
                Models.Vendor posted = repository.Add(added, ref messageError);

                if (posted != null)
                {
                    json = new
                    {
                        total   = 1,
                        data    = posted,
                        success = true
                    };
                }
                else
                {
                    json = new
                    {
                        message = messageError,
                        success = false
                    };
                };
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
        public object Put(JObject updatedJSON)
        {
            IDictionary <String, object> updated = updatedJSON.ToObject <IDictionary <String, object> >();

            object json;

            try
            {
                string        messageError = "";
                Models.Vendor putting      = repository.Update(updated, ref messageError);

                if (putting != null)
                {
                    json = new
                    {
                        total   = 1,
                        data    = putting,
                        success = true
                    };
                }
                else
                {
                    json = new
                    {
                        message = messageError,
                        success = false
                    };
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
        public object GetAll()
        {
            var queryValues = Request.RequestUri.ParseQueryString();

            int  page            = Convert.ToInt32(queryValues["page"]);
            int  start           = Convert.ToInt32(queryValues["start"]);
            int  limit           = Convert.ToInt32(queryValues["limit"]);
            int  id              = Convert.ToInt32(queryValues["id"]);
            int  orden           = Convert.ToInt32(queryValues["orden"]);
            bool onlyWithBalance = (queryValues["onlyWithBalance"] != null) ? Convert.ToBoolean(queryValues["onlyWithBalance"]) : false;

            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            int totalRecords = 0;

            try
            {
                if (id == 0)
                {
                    object json;
                    string msgError = "";
                    IList <Models.Vendor> lista;

                    lista = repository.GetList(onlyWithBalance, query, sort, page, start, limit, ref totalRecords, ref msgError);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    string        msgError = "";
                    Models.Vendor estatus  = repository.Get(id, ref msgError);

                    object json = new
                    {
                        data    = estatus,
                        success = true,
                        message = msgError
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }
Example #7
0
        public static Vendor From(Models.Vendor source)
        {
            var result = new Vendor().PopulateWith(source);

            return(result);
        }
Example #8
0
 public static object Single(Models.Vendor data, string userName)
 {
     return(DataProcess(data, userName));
 }