Esempio n. 1
0
        public HttpResponseMessage Post([FromBody] Models.region mRegion)
        {
            try
            {
                if (string.IsNullOrEmpty(mRegion.region_name))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "error", msg = "Region is Empty"
                    }, formatter));
                }
                if (mRegion.region_code.Length != 3)
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "error", msg = "Region code must be 3 character"
                    }, formatter));
                }
                else
                {
                    if (_regionRepository.CheckDuplicateRegions(mRegion))
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "error", msg = "Region Already Exists"
                        }, formatter));
                    }
                    else
                    {
                        region insert_region = new region
                        {
                            region_name = mRegion.region_name,
                            region_code = mRegion.region_code,
                            is_active   = mRegion.is_active,
                            created_by  = mRegion.created_by,
                            updated_by  = mRegion.updated_by
                        };

                        _regionRepository.AddRegion(insert_region);
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "success", msg = "Region save successfully"
                        }, formatter));
                    }
                }
            }
            catch (Exception ex)
            {
                var formatter = RequestFormat.JsonFormaterString();
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    output = "error", msg = ex.ToString()
                }, formatter));
            }
        }