示例#1
0
        public HttpResponseMessage Post([FromBody] Models.party_type party_type, long created_by)
        {
            try
            {
                if (string.IsNullOrEmpty(party_type.party_type_name.Trim()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "error", msg = "Party Type is Empty"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(party_type.party_prefix.Trim()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Party Prefix is Empty"
                    }, formatter));
                }
                else
                {
                    if (partyTypeRepository.CheckDuplicatPartyType(party_type.party_type_name))
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Party Type Already Exists"
                        }, formatter));
                    }
                    if (partyTypeRepository.CheckDuplicatPartyPrefix(party_type.party_prefix.ToUpper().Trim()))
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Party Prefix Already Exists"
                        }, formatter));
                    }
                    if (partyTypeRepository.CheckDuplicatPartyPrefix(party_type.party_prefix.ToLower().Trim()))
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Party Prefix Already Exists"
                        }, formatter));
                    }
                    else
                    {
                        Models.party_type insertPartyType = new Models.party_type
                        {
                            party_type_name = party_type.party_type_name.Trim(),
                            party_prefix    = party_type.party_prefix.ToUpper().Trim(),
                            created_by      = created_by,
                            created_date    = DateTime.Now,
                            is_deleted      = party_type.is_deleted = false,
                            is_active       = party_type.is_active = true
                        };
                        bool save_party_type = partyTypeRepository.InsertPartyType(insertPartyType, created_by);

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