Example #1
0
        public IHttpActionResult Saves(IEnumerable <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
                    }));
                }

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

                        dataItem = item.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
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.Repository, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }
Example #2
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
                }));
            }
        }
Example #3
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
                }));
            }
        }