Exemplo n.º 1
0
        public ActionResult MovementAuthorityYes(int?id)
        {
            if (id != null)
            {
                MovementPermision movementPermision = movementPermisionManager.GetById(id);
                Movement          aMovement         = new Movement();
                if (movementPermision != null)
                {
                    aMovement.AssetId          = movementPermision.AssetId;
                    aMovement.BranchId         = movementPermision.BranchId;
                    aMovement.BranchName       = movementPermision.BranchName;
                    aMovement.Id               = movementPermision.Id;
                    aMovement.MoveBy           = movementPermision.MoveBy;
                    aMovement.OrganizationId   = movementPermision.OrganizationId;
                    aMovement.OrganizationName = movementPermision.OrganizationName;
                    aMovement.RegistrationDate = movementPermision.RegistrationDate;

                    if (movementManager.Add(aMovement))
                    {
                        movementPermision.Permision = true;
                        movementPermisionManager.Update(movementPermision);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Entry(MovementEntryVM movementM)
        {
            var username = Session["username"].ToString();
            int orgid    = 0;
            var list     = userManager.GetAll().Where(c => c.UserName == username);

            foreach (var t in list)
            {
                orgid = t.OrganizationId;
            }

            ViewBag.orglist = organizationManager.GetAll();
            MovementEntryVM model = new MovementEntryVM()
            {
                OrganizationLookUp = loader.GetOrganizationByUserOrgIdSelectitems(orgid),
                //AssetLookUp = loader.GetAssetSelectListItems()
                AssetLookUp = loader.GetAssetSelectListItemsJoinwithAssetDetails(orgid)
            };

            string format = "d";

            model.RegistrationDate = DateTime.Today.ToString(format);
            List <MovementEntryVM> aList = (List <MovementEntryVM>)Session["CartList"];

            if (aList != null && aList.Any())
            {
                List <PdfView> pdfList = new List <PdfView>();
                foreach (var mo in aList)
                {
                    MovementEntryVM movementVM = new MovementEntryVM();
                    movementVM = mo;

                    movementVM.MoveBy = Session["username"].ToString();
                    AssetRegistrationDetails details = assetdetailsmanager.GetIdAssetId(movementVM.AssetId);
                    int detailsId = details.Id;
                    details = assetdetailsmanager.GetById(detailsId);
                    details.OrganizationId = movementVM.OrganizationId;
                    details.BranchId       = movementVM.OrganizationId;

                    var movement = Mapper.Map <Movement>(movementVM);

                    MovementPermision mvp = new MovementPermision();
                    mvp.Permision = false;
                    var  movementPermision = Mapper.Map <MovementPermision>(movementVM);
                    bool isSaved;
                    if (Session["Designation"].ToString() == "Manager")
                    {
                        isSaved = movementPermisionManager.Add(movementPermision);
                    }
                    else
                    {
                        isSaved = movementManager.Add(movement);
                    }



                    if (isSaved)
                    {
                        details.BranchId = movementVM.BranchId;
                        if (assetdetailsmanager.Update(details))
                        {
                            ModelState.Clear();
                            ViewBag.message = "Save Successfully";



                            PdfView aPdfView = new PdfView();

                            aPdfView.OrganizationId   = movement.OrganizationId;
                            aPdfView.OrganizationName = movement.OrganizationName;
                            aPdfView.AssetId          = movement.AssetId;
                            aPdfView.AssecCode        = movementVM.Code;
                            aPdfView.AssetSerialNo    = movementVM.SerialNo;
                            aPdfView.GeneralCategory  = movementVM.GeneralCategoryName;
                            aPdfView.Category         = movementVM.CategoryNme;
                            aPdfView.Brand            = movementVM.BrandName;
                            aPdfView.FromBranch       = movement.BranchName;
                            aPdfView.ToBranch         = branchManager.GetById(movement.BranchId).Name;
                            aPdfView.MovedBy          = movement.MoveBy;
                            aPdfView.Date             = movement.RegistrationDate;

                            pdfList.Add(aPdfView);
                        }
                    }
                }

                GeneratePdf(pdfList, DateTime.Now.Date.ToString(), Session["username"].ToString());
                Session["Printed"] = "YES";
            }

            return(RedirectToAction("Entry"));
        }