public IHttpActionResult SaveDevicSetting(DeviceSettingModel model) { var deviceModel = Mapper.Map <DeviceSettingModel, DeviceSetting>(model); var result = _UnitOfWork.DeviceSettingRepository.Create(deviceModel); _UnitOfWork.Commit(); return(Ok(result)); }
public async Task <IHttpActionResult> GetUserInfo(DeviceSettingModel model) { try { var userName = User.Identity.GetUserName(); var user = await GetApplicationUser(userName); if (user == null) { return(NotFound()); } var roles = await _repo.GetUserRoles(user.Id); var agentStatisticsModel = new AgentStatisticsModel(); if (roles.FirstOrDefault() == RolesEnum.Agent.ToString()) { agentStatisticsModel = await GetUserStatistic(user.Id); } model.ApplicationUserId = user.Id; var device = _UnitOfWork.DeviceSettingRepository.All() .Any(u => u.ApplicationUserId == model.ApplicationUserId && u.DeviceId == model.DeviceId); if (!device) { var deviceModel = Mapper.Map <DeviceSettingModel, DeviceSetting>(model); _UnitOfWork.DeviceSettingRepository.Create(deviceModel); _UnitOfWork.Commit(); } return(Ok(new UserEditViewmodel { Id = user.Id, UserName = user.UserName, FullName = user.FullName, Email = user.Email, PhoneNumber = user.PhoneNumber, Type = (int?)user.Type, CityId = user.CityId, PhotoUrl = user.PhotoUrl, Address = user.Address, CompanyName = user.Car != null ? user.Car.CompanyName : string.Empty, CarType = user.Car != null ? user.Car.Type : string.Empty, Model = user.Car != null ? user.Car.Model : string.Empty, Color = user.Car != null ? user.Car.Color : string.Empty, PlateNumber = user.Car != null ? user.Car.PlateNumber : string.Empty, PassengerNumberId = user.Car?.PassengerNumberId, IsSuspend = user.IsSuspend, IsNotified = user.IsNotified, Role = roles != null ? roles.First() : string.Empty, AgentStatisticsModel = agentStatisticsModel })); } catch (Exception e) { ErrorSaver.SaveError(e.Message); return(BadRequest(e.Message)); } }