예제 #1
0
        public JsonResult SendToApproval2(int idCapture, int approved, int pState, int pSoupK, int pStatus)
        {
            UserDTO userDto = (UserDTO)Session["userData"];

            SedesolServiceClient proxy       = new SedesolServiceClient();
            CaptureApprovalDTO   dto         = new CaptureApprovalDTO();
            List <CaptureDTO>    captureList = new List <CaptureDTO>();

            dto.Id_Capture = idCapture;
            dto.UserDto    = userDto;
            if (approved == 1)
            {
                dto.Id_Status = Convert.ToInt32(ConfigurationManager.AppSettings["stAprobada"].ToString());
            }
            else
            {
                dto.Id_Status = Convert.ToInt32(ConfigurationManager.AppSettings["stRechazada"].ToString());
            }
            dto.Id_User = userDto.Id;

            string resp = proxy.SendToApproval(dto);

            if (resp == "SUCCESS")
            {
                captureList = proxy.GetCapturesSearch(userDto.Id_User_Type, userDto.Id, pState, pSoupK, pStatus);
            }
            string viewContent = ConvertViewToString("CaptureList", captureList);

            return(Json(new { message = resp, PartialView = viewContent }));
        }
예제 #2
0
        public string Save(CaptureApprovalDTO dto, int approveStatus, int level)
        {
            using (SEDESOLEntities db = new SEDESOLEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        string msj = string.Empty;

                        CAPTURE_APPROVAL app = new CAPTURE_APPROVAL();
                        app.Id_Capture = dto.Id_Capture;
                        app.Id_User    = dto.Id_User;
                        app.Id_Status  = approveStatus;
                        app.CreateDate = DateTime.Now;

                        db.CAPTURE_APPROVAL.Add(app);

                        if (db.SaveChanges() > 0)
                        {
                            dto.Id = app.Id;
                            msj    = "SUCCESS";
                        }
                        else
                        {
                            return("ERROR");
                        }

                        CAPTURE b = db.CAPTUREs.FirstOrDefault(v => v.Id == dto.Id_Capture);
                        if (b != null)
                        {
                            b.Id_Status        = dto.Id_Status;
                            b.Id_LevelApproval = level;
                            db.SaveChanges();
                            msj = "SUCCESS";
                        }
                        else
                        {
                            transaction.Rollback();
                            return("ERROR");
                        }

                        transaction.Commit();
                        return(msj);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        return("ERROR");
                    }
                }
            }
        }
예제 #3
0
        public string SaveApproval(CaptureApprovalDTO dto)
        {
            string msg            = string.Empty;
            int    approvalStatus = 0;
            int    level          = 0;

            SoupKitchenDAO         skDao     = new SoupKitchenDAO();
            CaptureDAO             capDao    = new CaptureDAO();
            List <SkUserTypeDTOcs> listLevel = new List <SkUserTypeDTOcs>();

            //get current level of captura approval
            var capture = capDao.GetCaptureById(dto.Id_Capture);

            //get list of SK levels
            listLevel = skDao.GetUserTypeBySKId((int)capture.SoupKitchen.Id);
            //get top level approval
            var topApproval = listLevel.OrderByDescending(i => i.UserTypeDto.ApprovalOrder).Take(1);


            //validations

            if (dto.UserDto.Id_User_Type != 2)
            {
                if (listLevel.Count() == 0 || listLevel == null)
                {
                    msg = "El comedor no tiene niveles de aprobación asignados.";
                    return(msg);
                }

                //1. level of user in session is a part of levels of sk
                listLevel.Where(i => i.Id_UserType == dto.UserDto.Id_User_Type).ToList();
                if (listLevel.Count() == 0 || listLevel == null)
                {
                    msg = "Su usuario no tiene el nivel de aprobación permitido para este comedor.";
                    return(msg);
                }
                //validate if userType is equals to current level
                else if (dto.UserDto.Id_User_Type != capture.Id_LevelApproval)
                {
                    msg = "La captura se encuentra asignada para aprobación del nivel: " + capture.UserTypeDto.Description;
                    return(msg);
                }
            }

            if (dto.UserDto.Id_User_Type == 2)
            {
                //2. admin set status in approve by default, if not verify user level and appply status
                if (dto.Id_Status == 4)
                {
                    approvalStatus = 4;
                    dto.Id_Status  = 4;
                    level          = 2;
                }
                else
                {
                    approvalStatus = 5;
                    dto.Id_Status  = 6;
                    //return to kitchen top level
                    level = topApproval.FirstOrDefault().Id_UserType;
                }
            }
            else
            {
                //3. if level of user is top of sk set in approved, if not set in process of approval
                if (dto.Id_Status == 4)
                {
                    if (dto.UserDto.Id_User_Type == topApproval.FirstOrDefault().Id_UserType)
                    {
                        approvalStatus = 4;
                        dto.Id_Status  = 4;
                        level          = dto.UserDto.Id_User_Type;
                    }
                    else
                    {
                        approvalStatus = 4;
                        dto.Id_Status  = 6;
                        level          = dto.UserDto.Id_User_Type + 1;
                    }
                }
                else
                {
                    approvalStatus = 5;
                    dto.Id_Status  = 6;
                    if ((dto.UserDto.Id_User_Type - 1) > 2)
                    {
                        level = dto.UserDto.Id_User_Type - 1;
                    }
                    else
                    {
                        level = dto.UserDto.Id_User_Type;
                    }
                }
            }

            CaptureApprovalDAO dao = new CaptureApprovalDAO();

            //take dto.Id_Status
            return(dao.Save(dto, approvalStatus, level));
        }
예제 #4
0
        public string SendToApproval(CaptureApprovalDTO dto)
        {
            CaptureApprovalDAL dal = new CaptureApprovalDAL();

            return(dal.SaveApproval(dto));
        }