Esempio n. 1
0
        public HttpResponseMessage Post([FromBody] Models.area mArea)
        {
            try
            {
                if (string.IsNullOrEmpty(mArea.area_name))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "error", msg = "Area Name is Empty"
                    }, formatter));
                }



                if (_areaRepository.CheckDuplicateZoneArea(mArea))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "error", msg = "Same Area and Zone Already Exists! "
                    }, formatter));
                }
                else
                {
                    area insertArea = new area
                    {
                        area_name    = mArea.area_name,
                        area_code    = mArea.area_code,
                        region_id    = mArea.region_id,
                        is_active    = mArea.is_active,
                        created_by   = mArea.created_by,
                        created_date = DateTime.Now,
                        updated_by   = mArea.updated_by,
                        updated_date = DateTime.Now
                    };



                    _areaRepository.AddArea(insertArea);


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