Beispiel #1
0
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            IServiceScope      scope         = null;
            BlazeClientContext clientContext = null;

            try
            {
                //Create connection scope
                scope = _serviceScopeFactory.CreateScope();
                var messageHandler = scope.ServiceProvider.GetRequiredService <IBlazeMessageHandler>();

                clientContext = (BlazeClientContext)scope.ServiceProvider.GetRequiredService <ClientContext>();
                clientContext.ConnectionContext = connection;
                _clientManager.Add(clientContext);

                var reader = connection.CreateReader();
                var writer = connection.CreateWriter();

                while (true)
                {
                    try
                    {
                        var result = await reader.ReadAsync(_protocol);

                        var message = result.Message;

                        if (message != null)
                        {
                            var responses = await messageHandler.ProcessMessage(message, clientContext);

                            if (responses != null)
                            {
                                foreach (var response in responses)
                                {
                                    await writer.WriteAsync(_protocol, response);
                                }
                            }
                        }

                        if (result.IsCompleted)
                        {
                            break;
                        }
                    }
                    finally
                    {
                        reader.Advance();
                    }
                }
            }
            finally
            {
                if (clientContext != null)
                {
                    _clientManager.Remove(clientContext);
                }

                scope?.Dispose();
            }
        }
Beispiel #2
0
        public long Add(ClientModel client, TransitEditModel transit)
        {
            var id = _manager.Add(client, transit);

            _events.Add(id, EventType.ClientAdded, EventState.Emailing, client.Authentication.NewPassword);

            return(id);
        }
Beispiel #3
0
        public async Task <IActionResult> CreateClient([FromBody] ClientDTO client)
        {
            var createdClient = await _clientManager.Add(Mapper.Map <Client>(client), client.TenantId);

            if (createdClient.Item1 == null)
            {
                return(BadRequest(new BadRequestResponse(ModelState, ExceptionKeyHelper.GetString(createdClient.Item2.Value))));
            }
            return(CreatedAtAction("GetById", new { clientId = createdClient.Item1.ClientId, tenantId = client.TenantId }, new CreatedResponse(Mapper.Map <ClientDTO>(createdClient.Item1), 1)));
        }
Beispiel #4
0
        public virtual ActionResult Create(ClientModel model, [Bind(Prefix = "Transit")] TransitEditModel transitModel)
        {
            if (!EmailsHelper.Validate(model.Emails))
            {
                ModelState.AddModelError("Emails", @"Emails format is invalid");
            }

            if (!ModelState.IsValid)
            {
                BindBag(null);

                return(View());
            }

            long clientId        = 0;
            var  passwordDefined = !string.IsNullOrWhiteSpace(model.Authentication.NewPassword);

            if (passwordDefined)
            {
                try
                {
                    clientId = _manager.Add(model, transitModel);

                    if (model.ContractFile != null)
                    {
                        MergeContract(model, clientId);
                    }
                }
                catch (DublicateLoginException)
                {
                    ModelState.AddModelError("Login", Validation.LoginExists);
                }
            }
            else
            {
                ModelState.AddModelError("NewPassword", Validation.EmplyPassword);
            }

            if (!ModelState.IsValid)
            {
                BindBag(null);

                return(View());
            }

            return(RedirectToAction(MVC.Client.Edit(clientId)));
        }
Beispiel #5
0
        public void Test_Add()
        {
            var clientModel = _fixture.Build <ClientModel>()
                              .With(x => x.ContractDate, DateTimeProvider.Now.ToString())
                              .With(x => x.DefaultSenderId, TestConstants.TestSenderId)
                              .Create();
            var transitEditModel = _fixture.Create <TransitEditModel>();

            transitEditModel.CityId = TestConstants.TestCityId1;

            var clientId = _manager.Add(clientModel, transitEditModel);

            var clientData  = _clientRepository.Get(clientId);
            var transitData = _transitRepository.Get(clientData.TransitId).Single();

            clientData.ShouldBeEquivalentTo(
                clientModel,
                options => options.ExcludingMissingProperties()
                .Excluding(x => x.ContractDate)
                .Excluding(x => x.InsuranceRate));
            clientData.ContractDate.ToString().ShouldBeEquivalentTo(clientModel.ContractDate);
            clientData.InsuranceRate.ShouldBeEquivalentTo(clientModel.InsuranceRate / 100);
            transitData.ShouldBeEquivalentTo(transitEditModel, options => options.ExcludingMissingProperties());
        }
        public ActionResult AddNewClient(ViewCreateClientModel model, HttpPostedFileBase ClientImage, HttpPostedFileBase clientSignature)
        {
            try
            {
                var user   = (ViewUser)Session["user"];
                var client = Mapper.Map <ViewCreateClientModel, Client>(model);
                client.UserId = user.UserId;
                if (ClientImage != null)
                {
                    var ext = Path.GetExtension(ClientImage.FileName)?.ToLower();
                    if (ext == ".jpeg" || ext == ".jpg" || ext == ".png")
                    {
                        string image = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(2, 8) + ext;

                        string path = Path.Combine(
                            Server.MapPath("~/Images/Client/Photos"), image);
                        // file is uploaded
                        ClientImage.SaveAs(path);
                        client.ClientImage = "Images/Client/Photos/" + image;
                    }
                }

                if (clientSignature != null)
                {
                    string ext = Path.GetExtension(clientSignature.FileName)?.ToLower();
                    if (ext == ".jpeg" || ext == ".jpg" || ext == ".png")
                    {
                        string sign = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(2, 8) + ext;
                        string path = Path.Combine(
                            Server.MapPath("~/Images/Client/Signatures"), sign);
                        // file is uploaded
                        clientSignature.SaveAs(path);
                        client.ClientSignature = "Images/Client/Signatures/" + sign;
                    }
                }
                bool result = _iClientManager.Add(client);
                if (result)
                {
                    ViewBag.Message = "Saved Successfully!";
                }

                ViewBag.BranchId     = new SelectList(_iBranchManager.GetAllBranches(), "BranchId", "BranchName");
                ViewBag.RegionId     = new SelectList(_iRegionManager.GetAll(), "RegionId", "RegionName");
                ViewBag.ClientTypeId = new SelectList(_iCommonManager.GetAllClientType(), "ClientTypeId", "ClientTypeName");
                ViewBag.DistrictId   = new SelectList(_iDistrictManager.GetAll().ToList(), "DistrictId", "DistrictName");
                ViewBag.UpazillaId   = new SelectList(new List <Upazilla>(), "UpazillaId", "UpzillaName");
                ViewBag.PostOfficeId = new SelectList(new List <PostOffice>(), "PostOfficeId", "PostOfficeName");
                ViewBag.TerritoryId  = new SelectList(new List <Territory>(), "TerritoryId", "TerritoryName");
                return(View());
            }
            catch (Exception e)
            {
                Log.WriteErrorLog(e);
                if (e.InnerException != null)
                {
                    ViewBag.Error = e.Message + " <br /> System Error:" + e.InnerException.Message;
                }
                ViewBag.ClientTypes = _iCommonManager.GetAllClientType().ToList();
                ViewBag.Regions     = _iRegionManager.GetAll().ToList();
                return(View());
            }
        }
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            IServiceScope      scope         = null;
            BlazeClientContext clientContext = null;

            try
            {
                //Create connection scope
                scope = _serviceScopeFactory.CreateScope();
                var messageHandler = scope.ServiceProvider.GetRequiredService <IBlazeMessageHandler>();

                clientContext = (BlazeClientContext)scope.ServiceProvider.GetRequiredService <ClientContext>();
                clientContext.ConnectionContext = connection;
                clientContext.Reader            = connection.CreateReader();
                clientContext.Writer            = connection.CreateWriter();

                _clientManager.Add(clientContext);

                while (true)
                {
                    try
                    {
                        var result = await clientContext.Reader.ReadAsync(_protocol);

                        var message = result.Message;

                        if (message != null)
                        {
                            var response = await messageHandler.ProcessMessage(message);

                            if (response != null)
                            {
                                await clientContext.Writer.WriteAsync(_protocol, response);
                            }
                            //Send new notifications
                            while (clientContext.PendingNotifications.TryDequeue(out var notification))
                            {
                                await clientContext.Writer.WriteAsync(_protocol, notification);
                            }
                        }

                        if (result.IsCompleted)
                        {
                            break;
                        }
                    }
                    finally
                    {
                        clientContext.Reader.Advance();
                    }
                }
            }
            finally
            {
                if (clientContext != null)
                {
                    _clientManager.Remove(clientContext);
                }

                scope?.Dispose();
            }
        }
Beispiel #8
0
 public void Add(string connectionId, IClientProxy clientProxy)
 {
     _innerMgr.Add(connectionId, clientProxy);
 }
        public async Task <ActionResult> Create(Client client)
        {
            await Manager.Add(client);

            return(RedirectToAction(nameof(ShowClient)));
        }
Beispiel #10
0
 public async Task <DataResult> Post([FromBody] Client model)
 {
     return(await _clientManager.Add(model));
 }
        public ActionResult AddNewClient(FormCollection collection, HttpPostedFileBase file, HttpPostedFileBase ClientSignature)
        {
            int branchId  = Convert.ToInt32(Session["BranchId"]);
            int companyId = Convert.ToInt32(Session["CompanyId"]);

            try
            {
                var    user   = (ViewUser)Session["user"];
                Client client = new Client
                {
                    ClientName     = collection["ClientName"],
                    Address        = collection["Address"],
                    PostOfficeId   = Convert.ToInt32(collection["PostOfficeId"]),
                    ClientTypeId   = Convert.ToInt32(collection["ClientTypeId"]),
                    Phone          = collection["phone"],
                    AlternatePhone = collection["AlternatePhone"],
                    Gender         = collection["Gender"],
                    Fax            = collection["Fax"],
                    Email          = collection["Email"],
                    Website        = collection["Website"],
                    UserId         = user.UserId,
                    BranchId       = branchId,
                    NationalIdNo   = collection["NationalIdNo"],
                    TinNo          = collection["TinNo"],
                    TerritoryId    = Convert.ToInt32(collection["TerritoryId"]),
                    RegionId       = Convert.ToInt32(collection["RegionId"]),
                    CompanyId      = companyId
                };
                if (file != null)
                {
                    string ext   = Path.GetExtension(file.FileName);
                    string image = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(2, 8) + ext;
                    string path  = Path.Combine(
                        Server.MapPath("~/Images/Client/Photos"), image);
                    // file is uploaded
                    file.SaveAs(path);
                    client.ClientImage = "Images/Client/Photos/" + image;
                }
                else
                {
                    client.ClientImage = "";
                }
                if (ClientSignature != null)
                {
                    string ext  = Path.GetExtension(ClientSignature.FileName);
                    string sign = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(2, 8) + ext;
                    string path = Path.Combine(
                        Server.MapPath("~/Images/Client/Signatures"), sign);
                    // file is uploaded
                    ClientSignature.SaveAs(path);
                    client.ClientSignature = "Images/Client/Signatures/" + sign;
                }
                else
                {
                    client.ClientSignature = "";
                }
                bool result = _iClientManager.Add(client);
                ViewBag.ClientTypes = _iCommonManager.GetAllClientType().ToList();
                ViewBag.Regions     = _iRegionManager.GetAll().ToList();
                ViewBag.Message     = result;
                return(View());
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    ViewBag.Error = e.Message + " <br /> System Error:" + e.InnerException.Message;
                }
                ViewBag.ClientTypes = _iCommonManager.GetAllClientType().ToList();
                ViewBag.Regions     = _iRegionManager.GetAll().ToList();
                return(View());
            }
        }