Пример #1
0
        public HttpResponseMessage Put([FromBody] Models.party_type party_type, long updated_by)
        {
            try
            {
                if (string.IsNullOrEmpty(party_type.party_type_name.Trim()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", 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.Trim()))
                    {
                        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 updatePartyType = new Models.party_type

                        {
                            party_type_id   = party_type.party_type_id,
                            party_type_name = party_type.party_type_name.Trim(),
                            party_prefix    = party_type.party_prefix.ToUpper().Trim(),
                            updated_by      = updated_by,
                            updated_date    = DateTime.Now,
                            is_active       = true
                        };

                        bool irepoUpdate = partyTypeRepository.UpdatePartyType(updatePartyType, updated_by);

                        if (irepoUpdate == true)
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK,
                                                          new Confirmation {
                                output = "success", msg = "Party Type Updated successfully"
                            }, formatter));
                        }

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