Exemplo n.º 1
0
        public override Task <UpdateCategoryStateResponse> UpdateCategoryState(UpdateCategoryStateRequest request,
                                                                               ServerCallContext context)
        {
            UpdateCategoryStateResponse response;

            using (var priceContext = new pricecompContext())
            {
                var          updatedCatogories = request.UpdatedCategories;
                List <Int32> updatedRecord     = new List <Int32>();

                try
                {
                    foreach (var category in updatedCatogories)
                    {
                        var record =
                            priceContext.Stateassignment.FirstOrDefault(
                                item => item.Id == category.Id);

                        if (record != null)
                        {
                            record.State = category.Category;
                            priceContext.Update(record);
                            var res = priceContext.SaveChanges();

                            updatedRecord.Add(res);
                        }
                        else
                        {
                            updatedRecord.Add(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    response = (new UpdateCategoryStateResponse()
                    {
                        Status = "update state fail"
                    });
                }

                if (updatedRecord.Contains(0))
                {
                    response = (new UpdateCategoryStateResponse()
                    {
                        Status = "update state fail"
                    });
                }
                else
                {
                    response = (new UpdateCategoryStateResponse()
                    {
                        Status = "update state success"
                    });
                }
            }
            return(Task.FromResult(response));
        }
Exemplo n.º 2
0
        public override Task <UpdateCompetitorTierResponse> UpdateCompetitorTier(UpdateCompetitorTierRequest request, ServerCallContext context)
        {
            UpdateCompetitorTierResponse response;

            using (var priceContext = new pricecompContext())
            {
                var          updatedCompetitors = request.UpdatedCompetitor;
                List <Int32> updatedRecord      = new List <Int32>();

                try
                {
                    foreach (var competitor in updatedCompetitors)
                    {
                        var record =
                            priceContext.Competitor1.FirstOrDefault(
                                item => item.Competitorid == competitor.CompetitorId);

                        if (record != null)
                        {
                            record.Tier = competitor.UpdatedTier;
                            priceContext.Update(record);
                            var res = priceContext.SaveChanges();

                            updatedRecord.Add(res);
                        }
                        else
                        {
                            updatedRecord.Add(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    response = (new UpdateCompetitorTierResponse()
                    {
                        Status = "update tier fail"
                    });
                }

                if (updatedRecord.Contains(0))
                {
                    response = (new UpdateCompetitorTierResponse()
                    {
                        Status = "update tier fail"
                    });
                }
                else
                {
                    response = (new UpdateCompetitorTierResponse()
                    {
                        Status = "update tier success"
                    });
                }
            }
            return(Task.FromResult(response));
        }