Exemple #1
0
        public IHttpActionResult Put(string id, [FromBody] AD_CONFIG dataRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var    model = ModelState;
                    string msg   = VNPTResources.Instance.Get(model);

                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = msg
                    }));
                }

                var dataItem = this.Repository.GetQuery <AD_CONFIG>().FirstOrDefault(r => r.ID == id);
                if (dataItem is null)
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgNotFound)
                    }));
                }

                dataItem    = dataRequest.Clone();
                dataItem.ID = id;

                this.Repository.Update(dataItem);
                this.VNPTLogs.Write(this.Repository, EAction.Update, JsonConvert.SerializeObject(dataItem));
                this.Repository.UnitOfWork.SaveChanges();

                return(Json(new TResult()
                {
                    Status = (short)EStatus.Ok,
                    Data = dataItem
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.RepositoryLog, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }
Exemple #2
0
        public IHttpActionResult Post([FromBody] AD_CONFIG dataRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var    model = ModelState;
                    string msg   = VNPTResources.Instance.Get(model);

                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = msg
                    }));
                }

                if (this.Repository.GetQuery <AD_CONFIG>().Any(r => r.ID.Equals(dataRequest.ID)))
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), dataRequest.ID)
                    }));
                }

                var dataItem = dataRequest.Clone();

                this.Repository.Add(dataItem);
                this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem));
                this.Repository.UnitOfWork.SaveChanges();

                return(Json(new TResult()
                {
                    Status = (short)EStatus.Ok,
                    Data = dataItem
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.RepositoryLog, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }