public IActionResult AddDealerInformtion(DealerInformationVm entity)
        {
            if (User.Identity.IsAuthenticated)
            {
                var id   = User.Identity.Name;
                var user = _userService.GetUserByLoginId(id);
                entity.CreatedBy = user.UserId;
                entity.UpdatedBy = user.UserId;


                return(Ok(_dealerInformationServices.AddDealerInformation(entity)));
            }
            return(BadRequest());
        }
Exemple #2
0
        public string AddDealerInformation(DealerInformationVm entity)
        {
            string res = "";

            try
            {
                // DealerInformation obj = new DealerInformation();
                //if (entity.DealerId == 0)
                //{
                var obj          = _mapper.Map <DealerInformation>(entity);
                var locationList = new List <DealerWithLocationMapping>();

                if (entity.SelectedtItems != null)
                {
                    // var locationMapping = _repository.Get(s => s.DealerId == obj.DealerId);

                    foreach (var id in entity.SelectedtItems)
                    {
                        var loc = new DealerWithLocationMapping();

                        var existData = _unitOfWork.DealerWithLocationMapping.SingleOrDefault(s => s.DealerId == obj.DealerId && s.LocationId == id);
                        if (existData != null)
                        {
                            loc.DealerWithLocationMappingId = existData.DealerWithLocationMappingId;
                            loc.DealerId = existData.DealerId;
                        }
                        else
                        {
                            loc.DealerWithLocationMappingId = 0;
                            loc.DealerId = 0;
                        }

                        loc.LocationId = id;
                        locationList.Add(loc);
                    }
                    obj.DealerWithLocationMapping = locationList;
                }



                //}
                //else
                //{
                //    var obj = _mapper.Map<DealerInformation>(entity);
                //    var locationList = new List<DealerWithLocationMapping>();

                //    var locationMapping = _repository.Get(s => s.DealerId == obj.DealerId);
                //    if (locationMapping != null)
                //        foreach (var item in locationMapping)
                //        {

                //        }

                //    if (entity.SelectedtItems != null)
                //    {
                //        foreach (var id in entity.SelectedtItems)
                //        {
                //            var loc = new DealerWithLocationMapping();
                //            loc.LocationId = id;
                //            loc.DealerId = obj.DealerId;
                //            locationList.Add(loc);

                //        }
                //        obj.DealerWithLocationMapping = locationList;
                //    }
                //_repository.Update(obj);

                //}

                //  _repository.SaveChanges();
                //_UnitOfWork.SaveDealer(obj);
                // _unitOfWork.Commit();
                _unitOfWork.DealerInformation.SaveDealer(obj);
                res = "Success";
            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            return(res);
        }