public object GetService(Type oType) { return(ServicesHost.GetService( ApplicationName, oType )); }
public object GetService(Type oServiceType, string sInstanceName) { return(ServicesHost.GetService( ApplicationName, oServiceType, sInstanceName)); }
public object GetService(ITisServiceInfo serviceInfo, string sInstanceName) { return(ServicesHost.GetService( ApplicationName, serviceInfo.ServiceName, sInstanceName)); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { //// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. //// container.LoadConfiguration(); //// TODO: Register your types here container.RegisterType <IProjectDbContext, ProjectDbContext>(); //container.RegisterType(typeof(IEntityRepository<>), typeof(EntityRepository<>), new HierarchicalLifetimeManager()); container.RegisterType <IService, PhotoService>("SibersTestProject.Logic.BL.Service.PhotoService", new HierarchicalLifetimeManager()); container.RegisterType <IService, GalleryService>("SibersTestProject.Logic.BL.Service.GalleryService", new HierarchicalLifetimeManager()); container.RegisterType <IService, ImageService>("SibersTestProject.Logic.BL.Service.ImageService", new PerResolveLifetimeManager()); container.RegisterType <IService, CommentaryService>("SibersTestProject.Logic.BL.Service.CommentaryService", new PerResolveLifetimeManager()); container.RegisterType <IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager()); //container.RegisterType<IServicesHost, ServicesHost>(new HierarchicalLifetimeManager()); // register services host container.RegisterType <IServicesHost, ServicesHost>(new HierarchicalLifetimeManager(), new InjectionFactory(c => { var host = new ServicesHost(); var uow = c.Resolve <IUnitOfWork>(); c.Registrations .Where(item => item.RegisteredType == typeof(IService) && !item.MappedToType.IsInterface && !item.MappedToType.IsGenericType && !item.MappedToType.IsAbstract && !String.IsNullOrEmpty(item.Name)) .ForEach(item => c.Resolve <IService>(item.Name, new ResolverOverride[] { new ParameterOverride("servicesHost", host), new ParameterOverride("unitOfWork", uow) })); return(host); })); }
public ActionResult Edit(Guid id) { var gallery = ServicesHost.GetService <IGalleryService>().GetGalleryById(id); var galleryView = Mapper.Map <GalleryCreate>(gallery); return(View(galleryView)); }
public ActionResult Upload(PhotoUpload photoView, HttpPostedFileBase file) { try { if (ModelState.IsValid) { var arrayImage = ServicesHost.GetService <IImageService>().FileBaseToArray(file); photoView.UserId = User.Identity.GetUserId(); var photoModel = Mapper.Map <PhotoModel>(photoView); ServicesHost.GetService <IPhotoService>().SavePhoto(photoModel); ServicesHost.GetService <IImageService>().SaveImage(photoModel.EntityId, arrayImage); ViewBag.StateUpload = "Success upload"; } return(View()); } catch (NullReferenceException) { ViewBag.StateUpload = "ImageNotSelected"; return(View()); } catch (ExteptionTypeNotImage) { ViewBag.StateUpload = "FileTypeIsNotImage"; return(View()); } catch (Exception e) { ViewBag.StateUpload = e.Message; return(View()); } }
public ActionResult Edit(Guid id) { var photo = ServicesHost.GetService <IPhotoService>().GetById(id); var photoView = Mapper.Map <PhotoView>(photo); return(View(photoView)); }
public ActionResult CreatePhoto(GalleryCreatePhoto galleryView) { var newPhotos = galleryView.PhotoCheck.Where(a => a.Check == true).Select(a => a.EntityId).ToList(); ServicesHost.GetService <IGalleryService>().CreatePhoto(galleryView.EntityId, newPhotos); return(RedirectToAction("Index")); }
public JsonResult <ApiBaseResponse> SendCodeBySms(Guid userId, string phoneNumber) { var result = new ApiBaseResponse(); try { var user = Mapper.Map <OntextUser, ApiUser>(UserManager.FindById(userId)); if (user == null) { result.Status = Core.Enums.ApiStatusCode.WrongArgumentsOrData; } else { var purpose = IdentityUserTokenHelper.GenerateTokenPurpose(IdentityUserTokenHelper.TokenPurpose.Editing, phoneNumber); var token = UserManager.GenerateUserToken(purpose, user.Id); ServicesHost.GetService <ISmsService>().SendSmsMessage(phoneNumber, token); } } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public ActionResult ViewGallery(Guid id) { var galleryModel = ServicesHost.GetService <IGalleryService>().GetGalleryByIdWithPhotos(id); var galleryView = Mapper.Map <GalleryView>(galleryModel); return(View(galleryView)); }
public JsonResult <ApiBaseResponse> SendMessage([FromBody] ApiMessage message) { var result = new ApiBaseResponse(); try { var messageId = ServicesHost.GetService <IMessagesProvider>().Save(message); message = ServicesHost.GetService <IMessagesProvider>().GetById(messageId); var contact = ServicesHost.GetService <IContactsProvider>().GetById(message.ContactId); var receiverUser = UserManager.FindByPhoneNumber(contact.PhoneNumber); if (receiverUser == null) { var smsMessageText = message.GetSmsMessageText(message); ServicesHost.GetService <ISmsService>().SendSmsMessage(contact.PhoneNumber, smsMessageText); } else { var userDeviceTokens = ServicesHost.GetService <IDevicesProvider>().GetUserDevices(receiverUser.Id).Select(d => d.Token); var messagesCount = ServicesHost.GetService <IMessagesProvider>().UnreadUserMessagesCount(receiverUser.Id); var messageText = message.GetPushNotificationText(); Task.Run(() => ServicesHost.GetService <IApplePushNotificationService>().SendPushNotifications(userDeviceTokens, messageText, messagesCount, messageId.ToString())); } } catch (Exception ex) { result.Status = ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public ActionResult Edit(GalleryCreate galleryView) { var galleryModel = Mapper.Map <GalleryModelWithoutImage>(galleryView); galleryModel.UserId = User.Identity.GetUserId(); ServicesHost.GetService <IGalleryService>().Edit(galleryModel); return(RedirectToAction("Index")); }
public ActionResult Index() { var userId = AuthenticationManager.User.Identity.GetUserId(); var galleryModelList = ServicesHost.GetService <IGalleryService>().GetAllGalleryByUserId(userId); var galleryViewList = Mapper.Map <ICollection <GalleryModelWithoutImage>, ICollection <GalleryIndex> >(galleryModelList); return(View(galleryViewList)); }
public ActionResult Index() { var userId = AuthenticationManager.User.Identity.GetUserId(); var photoModelList = ServicesHost.GetService <IPhotoService>().GetAllUserPhoto(userId); var photoViewList = Mapper.Map <ICollection <PhotoModel>, ICollection <PhotoView> >(photoModelList); return(View(photoViewList)); }
public ActionResult DeletePhoto(Guid id) { var galleryModel = ServicesHost.GetService <IGalleryService>().GetGalleryByIdWithPhotos(id); var galleryView = Mapper.Map <GalleryCreatePhoto>(galleryModel); var userId = User.Identity.GetUserId(); galleryView.PhotoCheck = Mapper.Map <ICollection <PhotoModel>, ICollection <PhotoCheck> >(galleryModel.Photos).ToList(); return(View(galleryView)); }
public ActionResult Save(Guid id) { string contentType = "Image/jpeg"; byte[] image = ServicesHost.GetService <IImageService>().GetImageById(id, PhotoResolution.Original); if (image == null) { return(HttpNotFound()); } return(File(image, contentType, Guid.NewGuid().ToString() + ".jpg")); }
public ActionResult Edit(PhotoView photoView, HttpPostedFileBase file) { var photoModel = Mapper.Map <PhotoModel>(photoView); photoModel.UserId = User.Identity.GetUserId(); ServicesHost.GetService <IPhotoService>().Edit(photoModel); if (file != null) { ServicesHost.GetService <IImageService>().EditImage(photoModel.EntityId, file); } return(RedirectToAction("Index")); }
public JsonResult <ApiBaseResponse> LoginByPhone([FromUri] string phoneNumber) { var result = new ApiBaseResponse(); try { var user = Mapper.Map <OntextUser, ApiUser>(UserManager.FindByPhoneNumber(phoneNumber)); if (user == null) { var userEntity = new OntextUser(); var phone = ServicesHost.GetService <IPhonesProvider>().GetByPhoneNumber(phoneNumber) ?? new ApiPhone { Number = phoneNumber }; userEntity.UserName = Guid.NewGuid().ToString(); userEntity.TwoFactorEnabled = true; var userPassword = OntextSettings.UserDefaultPassword; var r = UserManager.Create(userEntity, userPassword); if (!r.Succeeded) { result.Status = Core.Enums.ApiStatusCode.WrongArgumentsOrData; return(Json(result)); } phone.UserId = userEntity.Id; ServicesHost.GetService <IPhonesProvider>().Save(phone); user = Mapper.Map <OntextUser, ApiUser>(UserManager.FindByPhoneNumber(phoneNumber)); } var purpose = IdentityUserTokenHelper.GenerateTokenPurpose(IdentityUserTokenHelper.TokenPurpose.Loging, phoneNumber); var token = UserManager.GenerateUserToken(purpose, user.Id); #if DEBUG UserManager.SendEmail(ConfigurationManager.AppSettings["Email"], "Security Code", token); #else UserManager.SendSms(phoneNumber, token); #endif } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // register Db context container.RegisterType <IOntextDbContext, OntextDbContext>(new HierarchicalLifetimeManager()); // register all repositories container .ConfigureAutoRegistration() .LoadAssemblyFrom(Assembly.GetExecutingAssembly().Location) .ExcludeAssemblies(a => !a.FullName.ToLowerInvariant().StartsWith("ontext.dal")) .Include((type) => type.Implements <ICustomRepository>() && type.IsClass && !type.IsAbstract && !type.IsGenericType, Then.Register().UsingLifetime <HierarchicalLifetimeManager>().As <ICustomRepository>().WithName(t => t.FullName)) .ApplyAutoRegistration(); // register all services container .ConfigureAutoRegistration() .LoadAssemblyFrom(Assembly.GetExecutingAssembly().Location) .ExcludeAssemblies(a => !a.FullName.ToLowerInvariant().StartsWith("ontext.bll")) .Include((type) => type.Implements <IService>() && type.IsClass && !type.IsAbstract && !type.IsGenericType, Then.Register().UsingLifetime <HierarchicalLifetimeManager>().As <IService>().WithName(t => t.FullName)) .ApplyAutoRegistration(); // register Unit of Work container.RegisterType <IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager(), new InjectionFactory(c => { var uow = new UnitOfWork(c.Resolve <IOntextDbContext>()); c.Registrations .Where(item => item.RegisteredType == typeof(ICustomRepository) && !item.MappedToType.IsInterface && !item.MappedToType.IsGenericType && !item.MappedToType.IsAbstract && !String.IsNullOrEmpty(item.Name)) .ForEach(item => c.Resolve <ICustomRepository>(item.Name, new ResolverOverride[] { new ParameterOverride("unitOfWork", uow) })); return(uow); })); // register services host container.RegisterType <IServicesHost, ServicesHost>(new HierarchicalLifetimeManager(), new InjectionFactory(c => { var host = new ServicesHost(); var uow = c.Resolve <IUnitOfWork>(); c.Registrations .Where(item => item.RegisteredType == typeof(IService) && !item.MappedToType.IsInterface && !item.MappedToType.IsGenericType && !item.MappedToType.IsAbstract && !String.IsNullOrEmpty(item.Name)) .ForEach(item => c.Resolve <IService>(item.Name, new ResolverOverride[] { new ParameterOverride("servicesHost", host), new ParameterOverride("unitOfWork", uow) })); return(host); })); }
public ActionResult Pagination(int page = 1) { if (page <= 0) { page = 1; } int pageSize = 5; int totalPage = 0; int totalRecord = 0; var userId = User.Identity.GetUserId(); var List = ServicesHost.GetService <IPhotoService>().Pagination(page, pageSize, out totalRecord, out totalPage, userId); ViewBag.dbCount = totalPage; return(View(List)); }
public JsonResult <ApiMessageResponse> GetUnreadByAccount(Guid id) { var result = new ApiMessageResponse(); try { result.Items = ServicesHost.GetService <IMessagesProvider>().GetUserMessages(id).ToList(); } catch (Exception ex) { result.Status = ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiPhoneResponse> GetByPhonesWithApp([FromUri] string[] phones) { var result = new ApiPhoneResponse(); try { result.Items = ServicesHost.GetService <IContactsProvider>().GetContactsWithApp(phones).ToList(); } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
/// <summary> /// Delete a contact /// </summary> /// <param name="id">Contact ID</param> /// <returns></returns> public JsonResult <ApiBaseResponse> Delete(Guid id) { var result = new ApiBaseResponse(); try { ServicesHost.GetService <IContactsProvider>().Delete(id); } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiContactResponse> GetByPhoneNumber(Guid userId, string phoneNumber) { var result = new ApiContactResponse(); try { result.Items = new[] { ServicesHost.GetService <IContactsProvider>().GetByPhoneNumber(userId, phoneNumber) }.ToList(); } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiContactResponse> GetByAccount(Guid id) { var result = new ApiContactResponse(); try { result.Items = ServicesHost.GetService <IContactsProvider>().GetContacts(id).ToList(); } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiBaseResponse> SaveUserSettings([FromBody] ApiSettings settings) { var result = new ApiBaseResponse(); try { ServicesHost.GetService <ISettingsProvider>().Save(settings); } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
/// <summary> /// Update a message /// </summary> /// <param name="value">Message to update</param> /// <returns></returns> public JsonResult <ApiBaseResponse> Put([FromBody] ApiMessage value) { var result = new ApiBaseResponse(); try { ServicesHost.GetService <IMessagesProvider>().Save(value); } catch (Exception ex) { result.Status = ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiBaseResponse> DeleteAll(Guid userId) { var result = new ApiBaseResponse(); try { ServicesHost.GetService <IMessagesProvider>().DeleteAll(userId); } catch (Exception ex) { result.Status = ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
public JsonResult <ApiPhoneResponse> GetUserPhones(Guid userId) { var result = new ApiPhoneResponse(); try { var userPhones = ServicesHost.GetService <IPhonesProvider>().GetUserPhoneNumbers(userId); result.Items = userPhones; } catch (Exception ex) { result.Status = Core.Enums.ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }
/// <summary> /// Get a specified message /// </summary> /// <param name="id">Message ID</param> /// <returns></returns> public JsonResult <ApiMessageResponse> Get(Guid id) { var result = new ApiMessageResponse(); try { var message = ServicesHost.GetService <IMessagesProvider>().GetById(id); result.Items = new[] { message }.ToList(); } catch (Exception ex) { result.Status = ApiStatusCode.SystemError; result.Error = ex.Message; } return(Json(result)); }