Exemple #1
0
        public HttpResponseMessage UpdateChamSoc([FromBody] ChamSocRequest request)
        {
            var response = new ChamSocResponse();

            if (BusinessHandler.TokenBUS.tokenCheck(request, response, 1))
            {
                ChamSocBUS.UpdateChamSoc(request, ref response);
                if (response.IsError)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                else
                {
                    if (ChamSocRepository.Update(request.Data) < 0)
                    {
                        response.Errors.Add("Lỗi hệ thống");
                        response.IsError = true;
                    }
                    else
                    {
                        response.Data = "Sửa thành công!";
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemple #2
0
        public HttpResponseMessage AddChamSoc([FromBody] ChamSocRequest request)
        {
            var response  = new ChamSocResponse();
            var tokendata = TokenBUS.tokenData(request, response, 1);

            if (!response.IsError)
            {
                ChamSocBUS.AddChamSoc(request, ref response);
                if (response.IsError)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                else
                {
                    ChamSoc cs = ChamSocRepository.IsExistsChamSoc(request.Data);
                    if (cs != null)
                    {
                        request.Data.MaChamSoc = cs.MaChamSoc;
                        ChamSocBUS.UpdateChamSoc(request, ref response);
                        if (response.IsError)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, response));
                        }

                        if (cs.LuongSua != request.Data.LuongSua)
                        {
                            if (!ChamSocBUS.UpdateMilk(request.Token, request.Data.LuongSua - cs.LuongSua))
                            {
                                response.Errors.Add("Lỗi hệ thống");
                                response.IsError = true;
                                return(Request.CreateResponse(HttpStatusCode.OK, response));
                            }
                        }

                        if (ChamSocRepository.Update(request.Data) < 0)
                        {
                            response.Errors.Add("Lỗi hệ thống");
                            response.IsError = true;
                        }
                        else
                        {
                            response.Data = "Sửa thành công!";
                        }
                    }
                    else
                    {
                        if (ChamSocBUS.UpdateMilk(request.Token, request.Data.LuongSua))
                        {
                            request.Data.MaChiNhanh = tokendata.AgencyId;
                            if (ChamSocRepository.Insert(request.Data) < 0)
                            {
                                response.Errors.Add("Lỗi hệ thống");
                                response.IsError = true;
                            }
                            else
                            {
                                response.Data = "Thêm thành công!";
                            }
                        }

                        else
                        {
                            response.Errors.Add("Lỗi hệ thống");
                            response.IsError = true;
                        }
                    }
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }