Exemplo n.º 1
0
            public async void SaveSelected(string POStatus, Action <int> Callback, string Remarks = "")
            {
                int NumberOfSelectedItem         = this.Where(t => t.isApproved == true).Count();
                int numberOfSuccessFullOperation = 0;
                int numberOfSaveCompleted        = 0;

                foreach (var model in this)
                {
                    if (model.isApproved == true)
                    {
                        ApprovalRepository repo = new ApprovalRepository();
                        int result = 0;

                        result = await repo.SavePOApprovalDetails(model.POID, bitopiApplication.User.UserCode,
                                                                  bitopiApplication.User.EmployeeName, POStatus,
                                                                  bitopiApplication.ApprovalType, bitopiApplication.ApprovalRoleType, Remarks);

                        numberOfSuccessFullOperation += result;
                        numberOfSaveCompleted++;
                        if (result == 1)
                        {
                            model.isDeleted = true;
                            //numberOfSuccessFullOperation++;
                        }

                        if (numberOfSaveCompleted == NumberOfSelectedItem)
                        {
                            Callback(numberOfSuccessFullOperation);
                        }
                    }
                }
            }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.refresh:
                var progressDialog = ProgressDialog.Show(this, null, "", true);
                new System.Threading.Thread(new ThreadStart(() =>
                {
                    ApprovalRepository repo = new ApprovalRepository();
                    //aprovalList = repo.GetApprovals(BitopiSingelton.Instance.User.UserCode).Result;
                    aprovalList = repo.GetApprovals(bitopiApplication.User.UserCode).Result;
                    RunOnUiThread(() =>
                    {
                        LoadView(aprovalList, progressDialog);
                    });
                })).Start();
                return(true);

            case Resource.Id.about:
                //BitopiSingelton.Instance.ShowAboutDialog(this);
                bitopiApplication.ShowAboutDialog(this);
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }
Exemplo n.º 3
0
 public ActionResult ApprovalContent(ApprovalTask _param)
 {
     ViewBag.ApprvalData = ApprovalRepository.SelApproval(new Approval {
         OID = _param.ApprovalOID
     });
     return(PartialView("Dialog/dlgApprovalContent"));
 }
Exemplo n.º 4
0
        protected async override void OnStart()
        {
            bitopiApplication.CurrentActivity = "Approval Detail Activity";
            base.OnStart();
            var progressDialog = ProgressDialog.Show(this, null, "", true);

            repo = new ApprovalRepository();

            List <ApprovalDetailsModel> aprovalList = await repo.GetPOApprovalDetails(bitopiApplication.User.UserCode, bitopiApplication.ApprovalRoleType,
                                                                                      bitopiApplication.ApprovalType);

            _approvalList.Clear();
            aprovalList.ForEach(s => _approvalList.Add(s));
            _approvalListAdapter = new ApprovalDetalisListAdapter(_approvalList, lvApprovalDetailList, this);
            lvApprovalDetailList.SetAdapter(_approvalListAdapter);
            _approvalListAdapter.NotifyDataSetChanged();
            _chkApproveAll.Click += (s, e) =>
            {
                _approvalList.ForEach(t => t.isApproved = _chkApproveAll.Checked);
                _approvalListAdapter.SetData(_approvalList);
                _approvalListAdapter.NotifyDataSetChanged();
            };
            lvApprovalDetailList.SetGroupIndicator(null);
            progressDialog.Dismiss();
        }
Exemplo n.º 5
0
        public void TestApprovalNewSplitDoesNotSave()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                var record = GetValid(9);
                record.Split = new Split();
                thisFar      = true;
                #endregion Arrange

                #region Act
                ApprovalRepository.DbContext.BeginTransaction();
                ApprovalRepository.EnsurePersistent(record);
                ApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Purchasing.Core.Domain.Split, Entity: Purchasing.Core.Domain.Split", ex.Message);
                throw;
            }
        }
Exemplo n.º 6
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.refresh:
                var progressDialog = ProgressDialog.Show(this, null, "", true);
                new Thread(new ThreadStart(() =>
                {
                    repo = new ApprovalRepository();

                    List <ApprovalDetailsModel> aprovalList = repo.GetPOApprovalDetails(bitopiApplication.User.UserCode, bitopiApplication.ApprovalRoleType,
                                                                                        bitopiApplication.ApprovalType).Result;

                    _approvalList.Clear();
                    aprovalList.ForEach(s => _approvalList.Add(s));


                    RunOnUiThread(() =>
                    {
                        _approvalListAdapter.NotifyDataSetChanged();
                        progressDialog.Dismiss();
                    });
                })).Start();
                return(true);

            case Resource.Id.about:
                bitopiApplication.ShowAboutDialog(this);
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }
Exemplo n.º 7
0
        public void TestApprovalWithNullOrderDoesNotSave()
        {
            var      thisFar = false;
            Approval record  = null;

            try
            {
                #region Arrange
                record       = GetValid(9);
                record.Order = null;

                thisFar = true;
                #endregion Arrange

                #region Act
                ApprovalRepository.DbContext.BeginTransaction();
                ApprovalRepository.EnsurePersistent(record);
                ApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsTrue(thisFar);
                Assert.AreEqual(record.Order, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The Order field is required.");
                Assert.IsTrue(record.IsTransient());
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
Exemplo n.º 8
0
 public JsonResult SelApproval(Approval _param)
 {
     if (_param.OID == null)
     {
         return(Json(ApprovalRepository.SelApprovals(_param)));
     }
     return(Json(null));
 }
        public void Setup()
        {
            _transactionScope   = new TransactionScope();
            _approvalRepository = new ApprovalRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);

            _domicile    = BuildMeA.Domicile("code", "description");
            _docType     = BuildMeA.DocType("code", "description");
            _subDocType1 = BuildMeA.SubDocType("code 1", "description 1").WithDocType(_docType);
            _manCo1      = BuildMeA.ManCo("description1", "code1").WithDomicile(_domicile);

            _document1 = BuildMeA.Document("id").WithDocType(_docType).WithSubDocType(_subDocType1).WithManCo(_manCo1);
            _approval  = BuildMeA.Approval("name", DateTime.Now).WithDocument(_document1);
        }
Exemplo n.º 10
0
            public void BtnNotApprove_click(object sender, EventArgs e)
            {
                ImageButton senderButton   = ((ImageButton)sender);
                string      PO             = senderButton.Tag.ToString();
                View        parentView     = (View)senderButton.Parent;
                int         ItemPostition  = (int)parentView.Tag;
                var         progressDialog = ProgressDialog.Show(_context, null, "", true);

                new Thread(new ThreadStart(() =>
                {
                    ApprovalRepository repo = new ApprovalRepository();
                    int result = 0;
                    result     = repo.SavePOApprovalDetails(PO, bitopiApplication.User.UserCode,
                                                            bitopiApplication.User.EmployeeName,
                                                            bitopiApplication.ApprovalRoleType == ApprovalRoleType.Approve ? "Rejected" : "NotRecommend",
                                                            bitopiApplication.ApprovalType, bitopiApplication.ApprovalRoleType, "").Result;
                    if (result == 1)
                    {
                        ////model.isDeleted = true;
                        //if (_approvalList.Count > 1)
                        //{
                        //    var tempModel = _approvalList.Where(er => er.POID == PO).First();
                        //    if (tempModel != null)
                        //        _approvalList.Remove(tempModel);
                        //}
                        //else
                        //    _approvalList = new ApprovalDetailList();
                        _approvalList.RemoveAt(ItemPostition);
                    }
                    //List<ApprovalDetailsModel> aprovalList = repo.GetPOApprovalDetails(bitopiApplication.User.UserCode, bitopiApplication.ApprovalRoleType,
                    //bitopiApplication.ApprovalType).Result;
                    //_approvalList.Clear();
                    //aprovalList.ForEach(s => _approvalList.Add(s));


                    _context.RunOnUiThread(() =>
                    {
                        if (result == 1 && _approvalList.Count == 0)
                        {
                            ((ApprovalDetailActivity)_context).rlMsg.Visibility            = ViewStates.Visible;
                            ((ApprovalDetailActivity)_context).rlapprovalDetail.Visibility = ViewStates.Gone;
                        }
                        NotifyDataSetChanged();
                        progressDialog.Dismiss();
                        Toast.MakeText(_context, PO + " has been " +
                                       ((bitopiApplication.ApprovalRoleType == ApprovalRoleType.Approve) ? "Rejected" : "Not Recommended")
                                       , ToastLength.Short).Show();
                    });
                })).Start();
            }
        public async Task <IEnumerable <Approval> > GetCharityApprovals(Expression <Func <Approval, bool> > predicate)
        {
            IEnumerable <Approval> lstApproval = null;

            var query = ApprovalRepository.GetWhereAsQueryable(predicate).OrderByDescending(a => a.Date);

            lstApproval = await query.ToListAsync();

            if (lstApproval == null || lstApproval.Count() == 0)
            {
                return(null);
            }

            return(lstApproval);
        }
        public async Task <IEnumerable <ApprovalResponseDto> > GetCharityApprovalResponseDto(Expression <Func <Approval, bool> > predicate)
        {
            List <Approval> lstApprovals = null;
            var             query        = ApprovalRepository.GetWhereAsQueryable(predicate).OrderByDescending(a => a.Date);

            lstApprovals = await query.ToListAsync();

            if (lstApprovals == null)
            {
                return(null);
            }

            var approvalsDto = this.Mapper.Map <IEnumerable <ApprovalResponseDto> >(lstApprovals);

            return(approvalsDto);
        }
Exemplo n.º 13
0
        public void TestIsExternalIsTrueSaves()
        {
            #region Arrange
            var approval = GetValid(9);
            approval.IsExternal = true;
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(approval);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsTrue(approval.IsExternal);
            Assert.IsFalse(approval.IsTransient());
            Assert.IsTrue(approval.IsValid());
            #endregion Assert
        }
Exemplo n.º 14
0
        public void TestApprovalWithNullSplitSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Split = null;
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(record);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(null, record.Split);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemplo n.º 15
0
        public void TestApprovalWithExistingOrderSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Order = Repository.OfType <Order>().Queryable.Single(a => a.Id == 2);
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(record);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(2, record.Order.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
        public async Task <Guid> CreateCharity(CharityCreateDto charityDto)
        {
            User user = new User(Guid.NewGuid(), charityDto.Login.ToLower(), charityDto.Password.ToSHA512(),
                                 LoginType.CHARITABLE_ENTITY, Guid.NewGuid(), true);

            var charitable = this.Mapper.Map <CharitableEntity>(charityDto);

            charitable.Status       = ApproverStatus.PENDING;
            charitable.IsActive     = false;
            charitable.ApproverData = null;
            charitable.Approver     = string.Empty;
            charitable.Id           = Guid.NewGuid();
            charitable.UserId       = user.Id;

            var approval = new Approval()
            {
                Id = Guid.NewGuid(),
                CharitableEntityId = charitable.Id,
                Date    = DateTime.UtcNow.ToBrazilianTimeZone(),
                Message = "Análise Pendente",
                Status  = (int)ApproverStatus.PENDING
            };

            var lstRole = await RoleRepository.GetWhereAsync(r => r.Name.ToLower().Equals("charitable_entity"));

            if (!lstRole.Any())
            {
                throw new Exception("Cannot find role charitable_entity");
            }

            await UserRoleRepository.AddAsync(new UserRole()
            {
                User = user, RoleId = lstRole.First().Id
            });

            await this.Repository.AddAsync(charitable);

            await ApprovalRepository.AddAsync(approval);

            await this.Repository.SaveAsync();

            return(charitable.Id);
        }
Exemplo n.º 17
0
        public void TestCompletedIsFalseSaves()
        {
            #region Arrange
            Approval approval = GetValid(9);
            approval.Completed = false;
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(approval);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(approval.Completed);
            Assert.IsFalse(approval.IsTransient());
            Assert.IsTrue(approval.IsValid());
            #endregion Assert
        }
Exemplo n.º 18
0
        public void TestApprovalWithExistingStatusCodeSaves()
        {
            #region Arrange
            var orderStatusCodeRepository = new RepositoryWithTypedId <OrderStatusCode, string>();
            var record = GetValid(9);
            record.StatusCode = orderStatusCodeRepository.Queryable.Single(a => a.Id == "2");
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(record);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("2", record.StatusCode.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemplo n.º 19
0
        public JsonResult SelApprovalHistory(DObject _param)
        {
            List <ApprovalTask> displayTask = new List <ApprovalTask>();
            Approval            approval    = ApprovalRepository.SelApproval(new Approval {
                TargetOID = _param.OID
            });

            if (approval != null)
            {
                approval.InboxStep.ForEach(step =>
                {
                    step.InboxTask.ForEach(task =>
                    {
                        task.Ord        = step.Ord;
                        task.CurrentNum = approval.CurrentNum;
                        displayTask.Add(task);
                    });
                });
            }
            return(Json(displayTask));
        }
Exemplo n.º 20
0
        public void TestApprovalWithExistingSplitSaves()
        {
            #region Arrange
            SplitRepository.DbContext.BeginTransaction();
            LoadSplits(3);
            SplitRepository.DbContext.CommitTransaction();
            var record = GetValid(9);
            record.Split = SplitRepository.Queryable.Single(a => a.Id == 3);
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(record);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(3, record.Split.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemplo n.º 21
0
        public void TestReroutePurchaserPostRedirectsWhenWrongStatus7()
        {
            #region Arrange
            var orders = new List <Order>();
            orders.Add(CreateValidEntities.Order(1));
            orders[0].StatusCode.SetIdTo(OrderStatusCode.Codes.Requester);
            new FakeOrders(0, OrderRepository, orders);
            #endregion Arrange

            #region Act
            var result = Controller.ReroutePurchaser(1, "test")
                         .AssertActionRedirect()
                         .ToAction <OrderController>(a => a.Review(1));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RouteValues["id"]);
            Assert.AreEqual("Order Status must be at account manager or purchaser to change purchaser.", Controller.ErrorMessage);
            ApprovalRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <Approval> .Is.Anything));
            OrderService.AssertWasNotCalled(a => a.ReRouteSingleApprovalForExistingOrder(Arg <Approval> .Is.Anything, Arg <User> .Is.Anything, Arg <bool> .Is.Anything));
            #endregion Assert
        }
        protected async override void OnStart()
        {
            var progressDialog = ProgressDialog.Show(this, null, "", true);

            //try
            // {
            base.OnStart();

            ApprovalRepository repo = new ApprovalRepository();

            aprovalList = await repo.GetApprovals(bitopiApplication.User.UserCode);

            RunOnUiThread(() =>
            {
                LoadView(aprovalList, progressDialog);
            });
            ///}
            //catch (System.Exception ex)
            //{
            //    progressDialog.Dismiss();
            //    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
            //}
        }
Exemplo n.º 23
0
        public void TestApprovalWithExistingSecondaryUserSaves()
        {
            #region Arrange
            var userRepository = new RepositoryWithTypedId <User, string>();
            userRepository.DbContext.BeginTransaction();
            LoadUsers(3);
            userRepository.DbContext.CommitTransaction();
            var record = GetValid(9);
            record.SecondaryUser = userRepository.Queryable.Single(a => a.Id == "2");
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(record);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("2", record.SecondaryUser.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
        public async Task UpdateCharity(Guid id, CharityUpdateDto charityDto, bool pending_data)
        {
            var charityModel     = Repository.GetWhereAsQueryable(c => c.Id.Equals(id)).First();
            var charitableEntity = this.Mapper.Map <CharitableEntity>(charityDto);

            charitableEntity.Id           = charityModel.Id;
            charitableEntity.Status       = charityModel.Status;
            charitableEntity.Approver     = charityModel.Approver;
            charitableEntity.ApproverData = charityModel.ApproverData;
            charitableEntity.IsActive     = charityModel.IsActive;
            charitableEntity.UserId       = charityModel.UserId;

            if (pending_data)
            {
                var approval = new Approval()
                {
                    Id = Guid.NewGuid(), CharitableEntityId = charityModel.Id, Date = DateTime.UtcNow.ToBrazilianTimeZone(), Message = "Análise Pendente", Detail = string.Empty, Status = (int)ApproverStatus.PENDING
                };

                await ApprovalRepository.AddAsync(approval);

                charitableEntity.ApproverData = DateTime.UtcNow.ToBrazilianTimeZone();
                charitableEntity.Approver     = string.Empty;
                charitableEntity.Status       = ApproverStatus.PENDING;
                charitableEntity.IsActive     = false;
            }
            else
            {
                charitableEntity.Name = charityModel.Name;
                charitableEntity.Cnpj = charityModel.Cnpj;
            }

            this.Repository.Udate(charitableEntity);

            await this.Repository.SaveAsync();
        }
Exemplo n.º 25
0
        void SendNotification(BitopiGcmMessage gcmMsg, string DeviceToken)
        {
            Dictionary <string, List <string> > ReceivingMessages;
            string            s = "";
            BitopiApplication bitopiApplication = (BitopiApplication)this.ApplicationContext;

            try
            {
                s = Newtonsoft.Json.JsonConvert.SerializeObject(gcmMsg);
                if (PushNotificationSingleton.Instance.ReadNotification() == "")
                {
                    ReceivingMessages = new Dictionary <string, List <string> >();
                }
                else
                {
                    string notiMsg = PushNotificationSingleton.Instance.ReadNotification();
                    ReceivingMessages = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(notiMsg);
                }
                string title = "", msgBody = "";

                // TytMoblieApplication application = (TytMoblieApplication)this.ApplicationContext;
                //BitopiGcmMessage gcmMsg = JsonConvert.DeserializeObject<BitopiGcmMessage>(message);
                string approvalName = gcmMsg.Approval == "1" ? "PO" :
                                      gcmMsg.Approval == "4" ? "Cash Requisition" : gcmMsg.Approval == "5" ? "Express Cash Requisition" : "";
                int requestID = Convert.ToInt16(gcmMsg.Approval);
                if (ReceivingMessages.Count > 0 && ReceivingMessages.ContainsKey(gcmMsg.Approval))
                {
                    ReceivingMessages[gcmMsg.Approval].Add(gcmMsg.POID);
                    msgBody = "You have " + ReceivingMessages[gcmMsg.Approval].Count() + " " + gcmMsg.ApprovalName + " to " + gcmMsg.ApprovalType;
                }
                else
                {
                    ReceivingMessages.Add(gcmMsg.Approval, new List <string> {
                        gcmMsg.POID
                    });
                    msgBody = "You have 1 " + gcmMsg.ApprovalName + " to " + gcmMsg.ApprovalType;
                }
                var totalNotification = 0;
                foreach (var msg in ReceivingMessages)
                {
                    totalNotification += msg.Value.Count;
                }


                try
                {
                    CrossBadge.Current.SetBadge(totalNotification);
                }
                catch { }

                //int result = repo.ReceiveNotification(bitopiApplication.User.UserCode,
                //    bitopiApplication.MacAddress,(ApprovalType)Convert.ToInt32(gcmMsg.Approval), gcmMsg.POID).Result;

                string approval = ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.PurchaseOrderApproval) ? "PO" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.CashRequisition) ? "Cash Requisition" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.LeaveApplication) ? "Leave Application" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.ChequeRequisitionInformation) ? "ChequeRequisition" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.ExpressCashRequisition) ? "ExpressCashRequisition" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.PORequisitionApproval) ? "PO Requisition" :
                                  ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.UnSeenTask) ? "UnSeenTask" : "";
                ApprovalRepository repo = new ApprovalRepository();
                string             url  = RepositorySettings.BaseURl + "Notification?userId=" +
                                          Cipher.Encrypt(bitopiApplication.User.UserCode) + "&deviceId=" +
                                          DeviceToken
                                          + "&approval=" + gcmMsg.ApprovalName + "&requisitioId="
                                          + gcmMsg.POID;

                HttpClient          client = new HttpClient();
                HttpResponseMessage result = client.GetAsync(url).Result;
                int count = JsonConvert.DeserializeObject <int>(result.Content.ReadAsStringAsync().Result);

                gcmMsg = new BitopiGcmMessage();
                //ISharedPreferences sp = PreferenceManager.GetDefaultSharedPreferences(this);
                //string employeeid = sp.GetString("employeeid_id", "");

                gcmMsg.DateCreated = DateTime.Now;
                Intent intent; intent = new Intent(this, typeof(StartupActivity));
                if ((ApprovalType)Convert.ToInt32(gcmMsg.Approval) == ApprovalType.UnSeenTask)
                {
                    intent = new Intent(this, typeof(MyTaskMenu));
                }
                intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(ApplicationContext, requestID, intent, 0);//requestID = DateTime.Now.Millisecond;
                var notificationBuilder = new NotificationCompat.Builder(this)
                                          .SetSmallIcon(BitopiApprovalSystem.Resource.Drawable.bitopiLogo)
                                          .SetContentTitle("Bitopi Approval System")
                                          .SetContentText(msgBody)
                                          .SetAutoCancel(true)
                                          .SetContentIntent(pendingIntent)
                                          .SetDefaults(NotificationCompat.DefaultSound);

                string toSaveNotiMsg = Newtonsoft.Json.JsonConvert.SerializeObject(ReceivingMessages);
                PushNotificationSingleton.Instance.SaveNotification(toSaveNotiMsg);
                var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

                //new UserRepository().GetNotificationCacheAsCompleted(gcmMsg.NotificationExecId);
                notificationManager.Notify(requestID, notificationBuilder.Build());
            }
            catch (Exception ex)
            {
                //CustomLogger.CustomLog("Line:" + Line + " From Activity: " + bitopiApplication.CurrentActivity + "\nMessage: " + s + "\nStack Trace: " + ex.StackTrace + "\n\n", "", bitopiApplication.User != null ?
                //         bitopiApplication.User.UserName : "");
            }
        }
Exemplo n.º 26
0
        public void TestReroutePurchaserWhenValid2()
        {
            #region Arrange
            SetupRoles();
            new FakeUsers(12, UserRepository);
            var orders = new List <Order>();
            orders.Add(CreateValidEntities.Order(1));
            orders[0].StatusCode.SetIdTo(OrderStatusCode.Codes.AccountManager);
            orders[0].Approvals.Add(CreateValidEntities.Approval(1));
            orders[0].Approvals[0].StatusCode.SetIdTo(OrderStatusCode.Codes.AccountManager);
            orders[0].Approvals[0].User = CreateValidEntities.User(99);
            orders[0].Workgroup.SetIdTo(2);
            orders[0].Approvals.Add(CreateValidEntities.Approval(1));
            orders[0].Approvals[0].StatusCode.SetIdTo(OrderStatusCode.Codes.Purchaser);
            orders[0].Approvals[0].User = CreateValidEntities.User(99);
            orders[0].Workgroup.Permissions.Add(CreateValidEntities.WorkgroupPermission(1));
            orders[0].Workgroup.Permissions.Add(CreateValidEntities.WorkgroupPermission(12));
            orders[0].Workgroup.Permissions[0].User    = UserRepository.Queryable.Single(a => a.Id == "1");
            orders[0].Workgroup.Permissions[0].Role    = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);
            orders[0].Workgroup.Permissions[1].User    = UserRepository.Queryable.Single(a => a.Id == "12");
            orders[0].Workgroup.Permissions[1].Role    = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);
            orders[0].Workgroup.Permissions[1].IsAdmin = true;
            new FakeOrders(0, OrderRepository, orders);


            //var orderPeeps = new List<OrderPeep>();
            //for (int i = 0; i < 12; i++)
            //{
            //    orderPeeps.Add(CreateValidEntities.OrderPeep(i + 1));
            //    orderPeeps[i].OrderId = 1;
            //    orderPeeps[i].WorkgroupId = 2;
            //    orderPeeps[i].OrderStatusCodeId = OrderStatusCode.Codes.Purchaser;
            //    orderPeeps[i].UserId = (i + 1).ToString();
            //}
            //orderPeeps[1].UserId = "99";
            //orderPeeps[2].OrderStatusCodeId = OrderStatusCode.Codes.AccountManager;
            //orderPeeps[3].OrderId = 9;
            //orderPeeps[4].WorkgroupId = 1;
            //orderPeeps[5].OrderStatusCodeId = OrderStatusCode.Codes.Approver;
            //orderPeeps[6].OrderStatusCodeId = OrderStatusCode.Codes.Requester;
            //orderPeeps[7].OrderStatusCodeId = OrderStatusCode.Codes.Cancelled;
            //orderPeeps[8].OrderStatusCodeId = OrderStatusCode.Codes.Complete;
            //orderPeeps[9].UserId = "1";
            //orderPeeps[10].UserId = "1";

            //new FakeOrderPeeps(0, OrderPeepRepository, orderPeeps);

            //var peeps = new List<OrderPeep>();
            //for (int i = 0; i < 10; i++)
            //{
            //    peeps.Add(CreateValidEntities.OrderPeep(i + 1));
            //    peeps[i].OrderId = 1;
            //    peeps[i].WorkgroupId = 2;
            //}
            #endregion Arrange

            #region Act
            var result = Controller.ReroutePurchaser(1, "1")
                         .AssertActionRedirect()
                         .ToAction <OrderController>(a => a.Review(1));
            #endregion Act

            #region Assert
            Assert.AreEqual("Order  rerouted to purchaser FirstName1 LastName1", Controller.Message);
            ApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(orders[0].Approvals[0]));
            OrderService.AssertWasCalled(a => a.ReRouteSingleApprovalForExistingOrder(orders[0].Approvals[0], UserRepository.Queryable.Single(b => b.Id == "1")));

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RouteValues["id"]);
            #endregion Assert
        }
Exemplo n.º 27
0
        public JsonResult PromoteApprovalTask(ApprovalTask _param)
        {
            try
            {
                DaoFactory.BeginTransaction();
                DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL_TASK, Convert.ToString(_param.BPolicyOID), Convert.ToInt32(_param.OID), Convert.ToInt32(_param.OID), _param.ActionType, "");
                ApprovalTaskRepository.UdtInboxTask(new ApprovalTask {
                    ActionType = _param.ActionType, Comment = _param.Comment, OID = _param.OID
                });

                if (_param.ActionType == CommonConstant.ACTION_REJECT)
                {
                    Approval tmpApproval = ApprovalRepository.SelApprovalNonStep(new Approval {
                        OID = _param.ApprovalOID
                    });
                    DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL, Convert.ToString(tmpApproval.BPolicyOID), Convert.ToInt32(tmpApproval.OID), Convert.ToInt32(tmpApproval.OID), _param.ActionType, "");

                    DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                        OID = tmpApproval.TargetOID
                    });
                    DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), _param.ActionType, "");
                    DaoFactory.Commit();
                    return(Json(CommonConstant.RETURN_SUCCESS));
                }

                bool         allSuccess      = true;
                ApprovalStep tmpApprovalStep = ApprovalStepRepository.SelApprovalStep(new ApprovalStep {
                    OID = _param.StepOID
                });
                tmpApprovalStep.InboxTask.ForEach(task =>
                {
                    if (task.BPolicy.Name != CommonConstant.POLICY_APPROVAL_COMPLETED)
                    {
                        allSuccess = false;
                    }
                });

                if (allSuccess)
                {
                    Approval tmpApproval = ApprovalRepository.SelApprovalNonStep(new Approval {
                        OID = _param.ApprovalOID
                    });
                    int cntCurrent = Convert.ToInt32(tmpApproval.CurrentNum);
                    cntCurrent += 1;
                    if (tmpApproval.ApprovalCount >= cntCurrent)
                    {
                        ApprovalRepository.UdtApproval(new Approval {
                            CurrentNum = cntCurrent, OID = tmpApproval.OID
                        });
                        ApprovalRepository.SelApproval(new Approval {
                            OID = tmpApproval.OID
                        }).InboxStep.Find(step => step.Ord == cntCurrent).InboxTask.ForEach(task =>
                        {
                            DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL_TASK, Convert.ToString(task.BPolicyOID), Convert.ToInt32(task.OID), Convert.ToInt32(task.OID), _param.ActionType, "");
                        });
                    }
                    else if (tmpApproval.ApprovalCount < cntCurrent)
                    {
                        ApprovalRepository.UdtApproval(new Approval {
                            CurrentNum = cntCurrent, OID = tmpApproval.OID
                        });
                        DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL, Convert.ToString(tmpApproval.BPolicyOID), Convert.ToInt32(tmpApproval.OID), Convert.ToInt32(tmpApproval.OID), _param.ActionType, "");

                        DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                            OID = tmpApproval.TargetOID
                        });
                        DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), _param.ActionType, "");
                    }
                }
                DaoFactory.Commit();
            }
            catch (Exception ex)
            {
                DaoFactory.Rollback();
                return(Json(new ResultJsonModel {
                    isError = true, resultMessage = ex.Message, resultDescription = ex.ToString()
                }));
            }
            return(Json(CommonConstant.RETURN_SUCCESS));
        }
        void SendNotification(BitopiGcmMessage gcmMsg)
        {
            try
            {
                string title = "", msgBody = "";

                // TytMoblieApplication application = (TytMoblieApplication)this.ApplicationContext;
                //BitopiGcmMessage gcmMsg = JsonConvert.DeserializeObject<BitopiGcmMessage>(message);
                string approvalName = gcmMsg.Approval == "1" ? "PO" :
                                      gcmMsg.Approval == "4" ? "Cash Requisition" : "";
                int requestID = Convert.ToInt16(gcmMsg.Approval);
                if (BitopiSingelton.Instance.ReceivingMessages.ContainsKey(gcmMsg.Approval))
                {
                    BitopiSingelton.Instance.ReceivingMessages[gcmMsg.Approval].Add(gcmMsg.POID);
                    msgBody = "You have " + BitopiSingelton.Instance.ReceivingMessages[gcmMsg.Approval].Count() + " " + approvalName + " to " + gcmMsg.ApprovalType;
                }
                else
                {
                    BitopiSingelton.Instance.ReceivingMessages.Add(gcmMsg.Approval, new List <string> {
                        gcmMsg.POID
                    });
                    msgBody = "You have 1 " + approvalName + " to " + gcmMsg.ApprovalType;
                }
                ApprovalRepository repo = new ApprovalRepository();
                int result = repo.ReceiveNotification(BitopiSingelton.Instance.User.UserCode,
                                                      BitopiSingelton.Instance.MacAddress, (ApprovalType)Convert.ToInt32(gcmMsg.Approval), gcmMsg.ApprovalName, gcmMsg.POID).Result;
                gcmMsg = new BitopiGcmMessage();
                //ISharedPreferences sp = PreferenceManager.GetDefaultSharedPreferences(this);
                //string employeeid = sp.GetString("employeeid_id", "");

                gcmMsg.DateCreated = DateTime.Now;
                Intent intent;


                intent = new Intent(this, typeof(StartupActivity));


                intent.AddFlags(ActivityFlags.ClearTop);

                var pendingIntent = PendingIntent.GetActivity(ApplicationContext, requestID, intent, 0);



                //requestID = DateTime.Now.Millisecond;
                var notificationBuilder = new NotificationCompat.Builder(this)
                                          .SetSmallIcon(BitopiApprovalSystem.Resource.Drawable.bitopiLogo)
                                          .SetContentTitle("Bitopi Approval System")
                                          .SetContentText(msgBody)
                                          .SetAutoCancel(true)
                                          .SetContentIntent(pendingIntent)
                                          .SetDefaults(NotificationCompat.DefaultSound);


                var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

                //new UserRepository().GetNotificationCacheAsCompleted(gcmMsg.NotificationExecId);
                notificationManager.Notify(requestID, notificationBuilder.Build());
            }
            catch (Exception ex)
            {
                CustomLogger.CustomLog("From Activity: " + BitopiSingelton.Instance.CurrentActivity + "\nMessage: " + ex.Message + "\nStack Trace: " + ex.StackTrace + "\n\n", "", BitopiSingelton.Instance.User != null ?
                                       BitopiSingelton.Instance.User.UserName : "");
            }
        }
Exemplo n.º 29
0
        public JsonResult InsApproval(Approval _param)
        {
            int result = 0;

            try
            {
                DaoFactory.BeginTransaction();

                DObject dobj = new DObject();
                if (_param.TargetOID == null)
                {
                    dobj.Type = CommonConstant.TYPE_SAVE_APPROVAL;
                    dobj.Name = _param.Name;
                }
                else
                {
                    dobj.Type = CommonConstant.TYPE_APPROVAL;
                    string strApprovalPrefix = dobj.Type + "-" + DateTime.Now.ToString("yyyyMMdd") + "-";
                    dobj.Name = strApprovalPrefix + SemsUtil.MakeSeq(DObjectRepository.SelNameSeq(new DObject {
                        Type = CommonConstant.TYPE_APPROVAL, Name = strApprovalPrefix + "%"
                    }), "000");
                    dobj.Description = _param.Description;
                }
                dobj.TableNm = CommonConstant.TABLE_APPROVAL;
                result       = DObjectRepository.InsDObject(dobj);

                _param.OID           = result;
                _param.ApprovalCount = _param.InboxStep.FindAll(step => step.ApprovalType.Equals(CommonConstant.TYPE_APPROVAL_APPROV) || step.ApprovalType.Equals(CommonConstant.TYPE_APPROVAL_AGREE)).Count;
                ApprovalRepository.InsApproval(_param);

                List <int> lPromoteOID = new List <int>();
                int        index       = 0;
                _param.InboxStep.ForEach(step =>
                {
                    step.ApprovalOID = result;
                    int stepResult   = ApprovalStepRepository.InsApprovalStep(step);

                    step.InboxTask.ForEach(task =>
                    {
                        if (dobj != null)
                        {
                            dobj = null;
                        }
                        dobj                     = new DObject();
                        dobj.Type                = CommonConstant.TYPE_APPROVAL_TASK;
                        dobj.TableNm             = CommonConstant.TABLE_APPROVAL_TASK;
                        string strApprovalPrefix = dobj.Type + "-" + DateTime.Now.ToString("yyyyMMdd") + "-";
                        dobj.Name                = strApprovalPrefix + SemsUtil.MakeSeq(DObjectRepository.SelNameSeq(new DObject {
                            Type = CommonConstant.TYPE_APPROVAL_TASK, Name = strApprovalPrefix + "%"
                        }), "000");
                        int taskResult = DObjectRepository.InsDObject(dobj);

                        task.ApprovalOID = result;
                        task.StepOID     = stepResult;
                        task.OID         = taskResult;
                        ApprovalTaskRepository.InsInboxTask(task);

                        if (index == 0)
                        {
                            lPromoteOID.Add(taskResult);
                        }
                    });
                    index++;
                });

                if (_param.TargetOID != null)
                {
                    DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                        OID = _param.TargetOID
                    });
                    DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), CommonConstant.ACTION_PROMOTE, null);
                    if (lPromoteOID != null && lPromoteOID.Count > 0)
                    {
                        lPromoteOID.ForEach(promoteOID =>
                        {
                            if (dobj != null)
                            {
                                dobj = null;
                            }
                            dobj = DObjectRepository.SelDObject(new DObject {
                                OID = promoteOID
                            });
                            DObjectRepository.StatusPromote(false, dobj.Type, Convert.ToString(dobj.BPolicyOID), Convert.ToInt32(dobj.OID), Convert.ToInt32(dobj.OID), CommonConstant.ACTION_PROMOTE, null);
                        });

                        DObject approvDobj = DObjectRepository.SelDObject(new DObject {
                            OID = result
                        });
                        DObjectRepository.StatusPromote(false, approvDobj.Type, Convert.ToString(approvDobj.BPolicyOID), Convert.ToInt32(approvDobj.OID), Convert.ToInt32(approvDobj.OID), CommonConstant.ACTION_PROMOTE, null);
                    }
                    ApprovalRepository.UdtApproval(new Approval {
                        OID = result, CurrentNum = 1
                    });
                }

                DaoFactory.Commit();
            }
            catch (Exception ex)
            {
                DaoFactory.Rollback();
                return(Json(new ResultJsonModel {
                    isError = true, resultMessage = ex.Message, resultDescription = ex.ToString()
                }));
            }
            return(Json(result));
        }
        public async Task UpdateCharityPending(Guid id, CharityApproveDto charityApproveDto)
        {
            var charityModel = Repository.GetWhereAsQueryable(c => c.Id.Equals(id)).First();
            var status       = (ApproverStatus)Enum.Parse(typeof(ApproverStatus), charityApproveDto.Status);

            var approval = new Approval()
            {
                Id = Guid.NewGuid(),
                CharitableEntityId = charityModel.Id,
                Date    = DateTime.UtcNow.ToBrazilianTimeZone(),
                Message = charityApproveDto.Message,
                Detail  = charityApproveDto.Detail,
                Status  = (int)status
            };

            await ApprovalRepository.AddAsync(approval);

            charityModel.ApproverData = DateTime.UtcNow.ToBrazilianTimeZone();
            charityModel.Approver     = charityApproveDto.ApproverName;
            charityModel.Status       = status;

            switch (status)
            {
            case ApproverStatus.PENDING_DATA:
            case ApproverStatus.APPROVED:
            case ApproverStatus.REPROVED:
                var lstUsers = await this.UserRepository.GetWhereAsync(u => u.Id == charityModel.UserId);

                var    user  = lstUsers.FirstOrDefault();
                string title = string.Empty;

                if (status == ApproverStatus.APPROVED)
                {
                    charityModel.IsActive = true;
                    title = "Doa Sonhos - Cadastro Aprovado";

                    if (user != null)
                    {
                        user.IsActive = true;
                        this.UserRepository.Udate(user);
                    }
                }
                else if (status == ApproverStatus.REPROVED)
                {
                    charityModel.IsActive = false;
                    title = "Doa Sonhos - Cadastro Reprovado";

                    if (user != null)
                    {
                        user.IsActive = false;
                        this.UserRepository.Udate(user);
                    }
                }
                else if (status == ApproverStatus.PENDING_DATA)
                {
                    charityModel.IsActive = false;
                    title = "Doa Sonhos - Correção Solicitada";

                    if (user != null)
                    {
                        user.IsActive = true;
                        this.UserRepository.Udate(user);
                    }
                }

                await this.SendEmail(user.Login, charityModel.Name, title, string.Format("Message: {0}\r\nDetalhes: {1}", approval.Message, string.IsNullOrWhiteSpace(approval.Detail)?"-":approval.Detail));

                break;

            default:
                charityModel.IsActive = false;
                break;
            }
            this.Repository.Udate(charityModel);

            await this.Repository.SaveAsync();
        }