Ejemplo n.º 1
0
        public HttpResponseMessage Delete([FromBody] Models.company objCompany)
        {
            try
            {
                bool deleteCompany = companyRepository.DeleteCompany(objCompany.company_id);

                var formatter = RequestFormat.JsonFormaterString();
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    output = "success", msg = "Company Delete Successfully."
                }, formatter));
            }
            catch (Exception ex)
            {
                var formatter = RequestFormat.JsonFormaterString();
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    output = "error", msg = ex.ToString()
                }, formatter));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post([FromBody] Models.company objCompany)
        {
            try
            {
                if (companyRepository.CheckDuplicateCompany(objCompany.company_name))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Company Name Already Exists"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.company_name))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Company Name is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.company_code))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Company Code is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.address))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Address is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.mobile))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Mobile is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.zip_code))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Zip Code is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.email))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Email is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.country_id.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Country is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(objCompany.city_id.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "City is Empty"
                    }, formatter));
                }
                else
                {
                    company insertCountry = new company
                    {
                        company_name = objCompany.company_name,
                        company_code = objCompany.company_code,
                        address      = objCompany.address,
                        mobile       = objCompany.mobile,
                        email        = objCompany.email,
                        zip_code     = objCompany.zip_code,
                        country_id   = objCompany.country_id,
                        city_id      = objCompany.city_id,
                        created_by   = objCompany.created_by,
                        created_date = DateTime.Now,
                        is_active    = true,
                        is_deleted   = false
                    };

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