Exemplo n.º 1
0
        public async Task <ActionResult> AddMatch(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Error: GroupId is null...!!!"));
            }

            var group = await db.Groups.FindAsync(id);

            if (group == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Error: Group is null...!!!"));
            }

            var match = new Match
            {
                DateTime      = DateTime.Today,
                GroupId       = group.GroupId,
                StatusMatchId = MethodsHelper.GetStatusMatchIdByName("Not Started", db),
            };

            //  Carga los ViewBag
            LoadViewBagsMatchTeams(match);

            return(View(match));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取群成员信息
        /// </summary>
        /// <param name="GroupList"></param>
        public static void GetGroupContactsMethod(List <MemberListItemEntity> GroupList)
        {
            GroupContacts GC = new GroupContacts();

            GC.BaseRequest = new BaseRequestEntity()
            {
                DeviceID = MethodsHelper.GetDeviceId(), Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, Uin = CommonDefine.LoginResult.wxuin
            };
            List <GroupListItem> GroupNumberList = new List <GroupListItem>();

            for (int index = 0; index < GroupList.Count; index++)
            {
                if (GroupList[index].UserName.Contains("@@"))
                {
                    GroupListItem Groupitem = new GroupListItem();
                    Groupitem.UserName = GroupList[index].UserName;
                    GroupNumberList.Add(Groupitem);
                }
            }
            GC.List  = GroupNumberList;
            GC.Count = GroupNumberList.Count;
            string PostData = JsonConvert.SerializeObject(GC);
            string Result   = HttpMethods.PostData(string.Format(UrlDefine.GetQunContactUrl, CommonDefine.LoginResult.pass_ticket), PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();

            if (!string.IsNullOrWhiteSpace(Result))
            {
                GroupMemberListEntity GroupMumberInfo = JsonConvert.DeserializeObject <GroupMemberListEntity>(Result);
                CommonDefine.GroupMemberList = GroupMumberInfo;
            }
            else
            {
                LogWriter.Write("获取群成员失败,返回结果为空!", LogPathDefine.WeChatGrouplogPath);
            }
            //GGC.List=new List<Entity.ListItem>(
        }
Exemplo n.º 3
0
        /// <summary>
        /// 对手机端信息进行同步
        /// </summary>
        /// <param name="FromUserName"></param>
        /// <param name="ToUserName"></param>
        public static void WebwxStatusNotify(string FromUserName, string ToUserName)
        {
            NotifyPhoneEntity Npe = new NotifyPhoneEntity();
            BaseRequestEntity br  = new BaseRequestEntity();

            br.DeviceID     = MethodsHelper.GetDeviceId();
            br.Sid          = CommonDefine.LoginResult.wxsid;
            br.Skey         = CommonDefine.LoginResult.skey;
            br.Uin          = CommonDefine.LoginResult.wxuin;
            Npe.BaseRequest = br;
            Random ran = new Random();

            Npe.ClientMsgId  = MethodsHelper.GetClientMsgId();// "1497590764" + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString();
            Npe.Code         = "1";
            Npe.FromUserName = FromUserName;
            Npe.ToUserName   = ToUserName;
            string PostData = JsonConvert.SerializeObject(Npe);
            string list     = HttpMethods.PostData(UrlDefine.WexNotifyUrl + CommonDefine.LoginResult.pass_ticket, PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();

            if (list != null)
            {
                SendMsgResultEntity Sre = JsonConvert.DeserializeObject <SendMsgResultEntity>(list);
                if (Sre.BaseResponse.Ret == 0)
                {
                }
                //if (list.Count >= 1)
                //{
                //    Console.WriteLine(list[0].ToString());
                //}
            }
        }
Exemplo n.º 4
0
        public void DownloadImage()
        {
            string uuid = MethodsHelper.HeadImageSaveFile(DirectoryDefine.HeaderImagePath, DisplayNameDef);

            if (File.Exists(Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg"))
            {
                HeadUrlDef = Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg";
                return;
            }
            if (string.IsNullOrWhiteSpace(HeadUrlDef))
            {
                HttpHelper.HttpMethods.GetFile(UrlDefine.RootUrl + HeadImgUrl, Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg", CommonDefine.Cookies);
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    FileInfo fileInfo = new FileInfo(Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg");
                    if (fileInfo.Length == 0)
                    {
                        HeadUrlDef = "pack://application:,,,/WeChatCore;component/Resource/DefultHeader.png";
                    }
                    else
                    {
                        HeadUrlDef = Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg";
                    }
                }));
            }
            else
            {
                LogWriter.Write(string.Format("当前人员{0}已有头像", DisplayNameDef), LogPathDefine.WeChatLogPath);
            }
        }
        private async void Delete()
        {
            if (await this.dialogService.ShowMessageConfirm(
                    "Infomation",
                    "Are you sure delete this record...?",
                    "Yes",
                    "No"))
            {
                //  Check the connections to internet
                var response = await this.apiService.CheckConnection();

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Generate an object
                var zoomDataItem = new ZoomDataItem
                {
                    Tracking   = this.Tracking,
                    UserId     = this.mainViewModel.UserData.UserId,
                    ZoomDataId = this.ZoomDataId,
                };

                //  Delete the record
                response = await this.apiService.Delete <ZoomDataItem>(
                    MethodsHelper.GetUrlAPI(),
                    "/api",
                    "/ZoomDatas",
                    this.mainViewModel.Token.TokenType,
                    this.mainViewModel.Token.AccessToken,
                    zoomDataItem);

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Delete record
                this.cantvViewModel.LoadUserData();

                await dialogService.ShowMessage(
                    "Infromation",
                    string.Format(
                        "Record: {0} remove successfully...!!!",
                        zoomDataItem.Tracking),
                    "Accept");
            }
        }
Exemplo n.º 6
0
        private async void FindData()
        {
            //  Sets status of controls
            this.SetStatusControl(false, true, "Green", 1);

            //  Validate the connections of internet
            var response = await this.apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Sets status of controls
                this.SetStatusControl(false, false, "Green", 0);
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Define the url parameter
            var ulrParameter = string.Format(
                "/{0}/{1}/{2}/{3}/{4}",
                this.ivssItemViewModel.NationalityDatas[0].Abbreviation,
                this.ivssItemViewModel.IdentificationCard,
                this.ivssItemViewModel.BirthDate.Day,
                this.ivssItemViewModel.BirthDate.Month,
                this.ivssItemViewModel.BirthDate.Year);

            //  Get data of the cne api
            response = await apiService.Get <Ivss>(
                MethodsHelper.GetUrlIvss(),
                "/infove/ivss",
                "/cuenta",
                ulrParameter);

            if (!response.IsSuccess)
            {
                //  Sets status of controls
                this.SetStatusControl(false, false, "Green", 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Load values in the control
            this.LoadValuesControls(1, (Ivss)response.Result);

            //  Sets status of controls
            if (isValid)
            {
                this.SetStatusControl(true, false, "Green", 0);
            }
        }
        private async void FindData()
        {
            //  Sets status of controls
            this.SetStatusControl(false, true, "Green", 1);

            //  Validate the connections of internet
            var response = await this.apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Sets status of controls
                this.SetStatusControl(false, false, "Green", 0);
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Define the url parameter
            var ulrParameter = string.Format(
                "/{0}",
                this.zoomItemViewModel.Tracking);

            //  Get data of the cne api
            response = await apiService.Get <Zoom>(
                MethodsHelper.GetUrlIvss(),
                "/infove/zoom",
                "/seguimiento",
                ulrParameter);

            if (!response.IsSuccess)
            {
                //  Sets status of controls
                this.SetStatusControl(false, false, "Green", 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Convert result response
            this.zoom = (Zoom)response.Result;

            //  Load values in the control
            //  this.LoadValuesControls(1, (Zoom)response.Result);
            this.LoadValuesControls(1, this.zoom);

            //  Sets status of controls
            if (isValid)
            {
                this.SetStatusControl(true, false, "Green", 0);
            }
        }
Exemplo n.º 8
0
        //  public async Task<ActionResult> Edit(Team team)
        public async Task <ActionResult> Edit(TeamView view)
        {
            if (ModelState.IsValid)
            {
                //if (view.ImageFile != null)
                //{
                //    MethodsHelper.Image = view.ImagePath;

                //    MethodsHelper.Image =
                //        FilesHelper.UploadPhoto(
                //            view.ImageFile,
                //            MethodsHelper.GetFolderSoccerFlag());

                //    MethodsHelper.Image =
                //        string.Format(
                //            "{0}{1}",
                //            MethodsHelper.GetFolderSoccerFlag(),
                //            MethodsHelper.Image);
                //}

                if (view.ImageFile != null)
                {
                    MethodsHelper.Image = view.ImagePath;

                    //  CEHJ - Guarda la imagen en el FTP
                    MethodsHelper.Image =
                        FilesHelper.UploadPhoto(
                            view.ImageFile,
                            MethodsHelper.GetFolderSoccerFlag(),
                            Convert.ToString(view.TeamId).Trim());

                    //  CEHJ - Da formato a la imagen
                    MethodsHelper.Image =
                        string.Format(
                            "{0}{1}",
                            MethodsHelper.GetFolderSoccerFlag(),
                            MethodsHelper.Image);
                }

                var team = TeamViewToTeam(view);
                team.ImagePath = MethodsHelper.Image;

                db.Entry(team).State = EntityState.Modified;
                response             = await DbHelper.SaveChangeDB(db);

                if (response.IsSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, response.Message);
                }
            }

            //  return View(team);
            return(View(view));
        }
Exemplo n.º 9
0
        private async void LoadData()
        {
            //  Set status of controls
            this.SetStatusControl(false, true, 1);

            //  Validate the connections of internet
            var response = await this.apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Set status of controls
                this.SetStatusControl(true, false, 0);
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Find the values of the Nationality
            response = await this.apiService.GetList <NationalityData>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Nationalities",
                "",
                this.mainViewModel.Token.TokenType,
                this.mainViewModel.Token.AccessToken);

            if (!response.IsSuccess)
            {
                //  Set status of controls
                this.SetStatusControl(true, false, 0);
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //
            this.listNationalities =
                new List <NationalityData>((List <NationalityData>)response.Result);

            //  Load to values the ObservableCollection
            this.Nationalities =
                new ObservableCollection <NationalityData>(
                    listNationalities.OrderBy(n => n.NationalityId));

            //  Load the values in the fields
            this.NationalityId      = this.cneItemViewModel.NationalityId;
            this.IdentificationCard = this.cneItemViewModel.IdentificationCard;

            //  Set status of controls
            this.SetStatusControl(true, false, 0);
        }
Exemplo n.º 10
0
        private bool IsAnyPointPrettyCloseToRoot(TFunc func, Conditions conditions, IEnumerable <double> actualPoints)
        {
            if (!actualPoints.IsEnoughOfParams(1))
            {
                MethodsHelper.ThrowGreedlyException(actualPoints, 1);
            }

            return(IsPrettyClose(func.Compute(actualPoints.Last()) / MinimumOfOnceDiff, conditions));
        }
Exemplo n.º 11
0
        private async void LoadValues()
        {
            //  this.Nationality = "";
            this.IdentificationCard = "";
            //  this.BirthDate = DateTime.Now.Date;

            //  Define the status of the controls
            this.SetStatusControl(false, true, 1);

            var response = await this.apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Define the status of the controls
                this.SetStatusControl(true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Get an List<> of the Nationalities
            response = await this.apiService.GetList <NationalityData>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Nationalities",
                "",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken);

            if (!response.IsSuccess)
            {
                //  Define the status of the controls
                this.SetStatusControl(true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            this.listNationalities =
                new List <NationalityData>((List <NationalityData>)response.Result);

            this.Nationalities =
                new ObservableCollection <NationalityData>(
                    listNationalities.OrderBy(n => n.NationalityId));

            //  Define the status of the controls
            this.SetStatusControl(true, false, 0);
        }
Exemplo n.º 12
0
        private void LoadData()
        {
            //  Set status of controls
            this.SetStatusControl(true, false, 0);

            //  Load data in the fields
            this.AppName         = "BCS-VzLaApp";
            this.AppVersion      = "Pre Beta Ver. 1.0.0.0";
            this.AppLicense      = "Test, with registration limit";
            this.AppDevCompany   = MethodsHelper.GetCompanyName();
            this.AppWebPage      = MethodsHelper.GetCompanyUrl();
            this.AppEmailCompany = MethodsHelper.GetCompanyEmail();
        }
Exemplo n.º 13
0
        // GET: CantvDatas
        public async Task <ActionResult> Index()
        {
            var appName    = MethodsHelper.GetAppNameGetServices();
            var cantvDatas = await db.CantvDatas
                             .Include(c => c.User)
                             .OrderBy(c => c.UserId)
                             .ThenBy(c => c.CodePhone)
                             .ThenBy(c => c.NumberPhone)
                             .Where(c => c.User.AppName == appName)
                             .ToListAsync();

            //  return View(await cantvDatas.ToListAsync());
            return(View(cantvDatas));
        }
Exemplo n.º 14
0
 private void LoadValuesControls(int _option, Ivss _ivssData)
 {
     if (_option == 0)
     {
         this.IdentificationCard = string.Empty;
         this.FullName           = string.Empty;
         this.BirthDate          = string.Empty;
         this.EmployerNumber     = string.Empty;
         this.Company            = string.Empty;
         this.Entry       = string.Empty;
         this.Status      = string.Empty;
         this.Membership  = string.Empty;
         this.Contingency = string.Empty;
         this.Weeks       = string.Empty;
         this.Salaries    = string.Empty;
     }
     else
     {
         if (!_ivssData.Descripcion.Contains(
                 "la Cedula no esta registrada como asegurado"))
         {
             this.IdentificationCard = _ivssData.Cedula;
             this.FullName           =
                 MethodsHelper.TitleText(_ivssData.Nombre.Trim());
             this.Gender =
                 MethodsHelper.TitleText(_ivssData.Sexo.Trim());
             this.BirthDate      = _ivssData.Nacimiento.Trim();
             this.EmployerNumber =
                 MethodsHelper.TitleText(_ivssData.NumeroPatronal.Trim());
             this.Company = _ivssData.Empresa.Trim();
             this.Entry   = _ivssData.Ingreso.ToUpper().Trim();
             this.Status  =
                 MethodsHelper.TitleText(_ivssData.Estatus.Trim());
             this.Membership  = _ivssData.Afiliacion.Trim();
             this.Contingency = _ivssData.Contingencia.Trim();
             this.Weeks       = _ivssData.Semanas.Trim();
             this.Salaries    = _ivssData.Salarios.Trim();
         }
         else
         {
             this.MessageLabel = _ivssData.Descripcion;
             //  Sets status of controls
             this.isValid = false;
             this.SetStatusControl(true, false, "Red", -1);
         }
     }
 }
Exemplo n.º 15
0
        //  public async Task<ActionResult> Edit(User user)
        public async Task <ActionResult> Edit(UserView userView)
        {
            if (ModelState.IsValid)
            {
                //  CHEJ - Inicializa la variable de imagen
                MethodsHelper.Image = userView.ImagePath;

                //  CHEJ - Valida si el usuario cambio de imagen
                if (userView.ImageFile != null)
                {
                    //  CHEJ - Sube la imagen al FTP
                    MethodsHelper.Image =
                        FilesHelper.UploadPhoto(
                            userView.ImageFile,
                            MethodsHelper.GetPathUserImages(),
                            Convert.ToString(userView.UserId).Trim());

                    //  CHEJ - Da formato a la imagen
                    MethodsHelper.Image =
                        string.Format(
                            "{0}{1}",
                            MethodsHelper.GetPathUserImages(),
                            MethodsHelper.Image);
                }

                //  CHEJ - Actualiza la ruta de la imagen
                userView.ImagePath = MethodsHelper.Image;

                //  CHEJ - Transforma el objeto de UserView a User
                var user = UserViewToUser(userView);

                db.Entry(user).State = EntityState.Modified;
                response             = await DbHelper.SaveChangeDB(db);

                if (response.IsSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }

            //  CHEJ - Hace la carga de datos de los ViewBag
            LoadViewBagUserType(null, userView.UserTypeId);

            return(View(userView));
        }
Exemplo n.º 16
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="Fe">文件类型</param>
        /// <param name="FileData">文件byte</param>

        public static void SendFile(FileEntity Fe, byte[] FileData)
        {
            Fe.BaseRequest = new BaseRequestEntity()
            {
                DeviceID = MethodsHelper.GetDeviceId(), Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey
            };
            string Boundary = "------WebKitFormBoundaryUOlSZtOip6JP4NSr";

            HttpMethods.AddContent("id", "WU_FILE_0", Boundary);
            HttpMethods.AddContent("name", Fe.FileName, Boundary);
            HttpMethods.AddContent("type", Fe.FileType, Boundary);
            HttpMethods.AddContent("lastModifiedDate", Fe.FileModiftTime.ToLocalTime().ToString(), Boundary);
            HttpMethods.AddContent("size", Fe.DataLen.ToString(), Boundary);
            HttpMethods.AddContent("mediatype", Fe.Mediatype1, Boundary);
            HttpMethods.AddContent("uploadmediarequest", JsonConvert.SerializeObject(Fe), Boundary);
            HttpMethods.AddContent("webwx_data_ticket", CommonDefine.GetCookieDictionary == null ? "" : CommonDefine.GetCookieDictionary["webwx_data_ticket"], Boundary); //"gScOa2YvEEtszEvhoxdwXCeg"
            HttpMethods.AddContent("pass_ticket", CommonDefine.LoginResult.pass_ticket, Boundary);                                                                        //"ekYYf2P7xOH5iI+oYrf/GiGrZhE+fUEGMiXe3Pq71rb4MDe+7ICbD+kglD4ZE+Ey"
            HttpMethods.AddContent("filename", Fe.FileName, Fe.FileType, FileData, Boundary);
            HttpMethods.OptionsDataMulitData(UrlDefine.SendFileUrl, CommonDefine.Cookies, Encoding.UTF8, Boundary);
            HttpMethods.PostDataMulitData(UrlDefine.SendFileUrl, CommonDefine.Cookies, Encoding.UTF8, Boundary);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="Msg">消息体</param>
        /// <param name="IsAddChatList">是否添加到聊天列表</param>
        /// <param name="ToName">向谁发送</param>
        public static bool SendToOtherMsg(string Msg = "", string ToName = "")
        {
            string SendMsg    = string.Empty;
            string LocalMsgId = MethodsHelper.GetClientMsgId();

            if (!string.IsNullOrWhiteSpace(Msg))
            {
                SendMsg = Msg;
            }
            string            chaturl = UrlDefine.ChatUrl + CommonDefine.LoginResult.pass_ticket;
            SendMsgBodyEntity Smbe    = new SendMsgBodyEntity()
            {
                BaseRequest = new BaseRequestEntity()
                {
                    DeviceID = MethodsHelper.GetDeviceId(), Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey
                }, Msg = new SendMsgEntity()
                {
                    Type = MsgTypeEnum.Text, FromUserName = CommonDefine.BaseContact.User.UserName, ToUserName = ToName, Content = Msg, LocalID = LocalMsgId, ClientMsgId = LocalMsgId
                }
            };
            string PostData         = JsonConvert.SerializeObject(Smbe);
            string Result           = HttpMethods.PostData(chaturl, PostData, CommonDefine.Cookies, Encoding.UTF8, "AcceptEncoding", "gzip, deflate").ContentData.ToString();
            SendMsgResultEntity Sre = JsonConvert.DeserializeObject <SendMsgResultEntity>(Result);

            if (Sre.BaseResponse.Ret == 0)
            {
                //消息发送成功
                CommonMethodCallBackHandlers.OnSendMsgCompleted(true);
                return(true);
            }
            else
            {
                Console.WriteLine("发送失败:" + Result);
                CommonMethodCallBackHandlers.OnSendMsgCompleted(false);
                return(false);
            }
        }
Exemplo n.º 18
0
        private async void Save()
        {
            //  Validate the fields of the form
            if (this.NationalityId == 0)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    "You must select an nationality...!!!",
                    "Accept");

                return;
            }

            var response = MethodsHelper.IsValidField(
                "I",
                8,
                8,
                "identification card",
                this.IdentificationCard,
                true,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Define the status of the controls
            this.SetStatusControl(false, true, 1);

            //  Check the connection internet
            response = await this.apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Define the status of the controls
                this.SetStatusControl(true, false, 0);
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            // Create the object
            var cneIvssData = new CneIvssDataItem
            {
                //  BirthDate = this.BirthDate,
                BirthDate          = DateTime.Today.Date,
                IdentificationCard = this.IdentificationCard,
                IsCne         = true,
                IsIvss        = false,
                NationalityId = this.NationalityId,
                UserId        = this.mainViewModel.UserData.UserId,
            };

            response = await this.apiService.Post <CneIvssDataItem>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/CneIvssDatas/PostCneIvssDataInsertByOption/?_option=cne",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                cneIvssData);

            if (!response.IsSuccess)
            {
                //  Define the status of the controls
                this.SetStatusControl(true, false, 0);
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Add record to CneData
            this.cantvViewModel.UpdateCneData(
                1,
                this.ToCneItemViewModel((CneIvssDataItem)response.Result));

            //  Navigate to back
            await this.navigationService.GoBackOnMaster();

            //  Define the status of the controls
            this.SetStatusControl(true, false, 0);
        }
Exemplo n.º 19
0
        private async Task <User> CheckUserAsync(
            string _userName,
            string _password,
            string _firtsName,
            string _lastName,
            string _phoneNumber,
            string _address,
            string _cityDescription,
            string _role)
        {
            #region Admin User / Role

            var user = await this.iUserHelper.GetUserByEmailAsync(
                _userName);

            if (user == null)
            {
                user = new User
                {
                    FirstName   = _firtsName,
                    LastName    = _lastName,
                    Email       = _userName,
                    UserName    = _userName,
                    PhoneNumber = _phoneNumber,
                    Address     = _address,
                    CityId      = MethodsHelper.GetCityIdByDescription(_cityDescription, context),
                    City        = MethodsHelper.GetCityByDescription(_cityDescription, context),
                };

                var result = await this.iUserHelper.AddUserAsync(
                    user,
                    _password);

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Could not create the user in seeder");
                }

                await this.iUserHelper.AddUserToRoleAsync(
                    user,
                    _role);
            }

            //  var chanePassword = await this.iUserHelper.ChangePasswordAsync(user, "123456", "Chej5654.");

            var isInRole = await this.iUserHelper.IsUserInRoleAsync(
                user,
                _role);

            if (!isInRole)
            {
                await this.iUserHelper.AddUserToRoleAsync(
                    user,
                    _role);
            }

            #region Confirm Email

            var token = await this.iUserHelper.GenerateEmailConfirmationTokenAsync(user);

            await this.iUserHelper.ConfirmEmailAsync(user, token);

            #endregion Confirm Email

            #endregion Admin User / Role

            return(user);
        }
        private async void Delete()
        {
            if (await this.dialogService.ShowMessageConfirm(
                    "Infomation",
                    "Are you sure delete this record...?",
                    "Yes",
                    "No"))
            {
                //  Check the connections to internet
                var response = await this.apiService.CheckConnection();

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Generate an object
                var cneIvssDataItem = new CneIvssDataItem
                {
                    BirthDate          = this.BirthDate,
                    CneIvssDataId      = this.CneIvssDataId,
                    IdentificationCard = this.IdentificationCard,
                    IsCne            = this.IsCne,
                    IsIvss           = this.IsIvss,
                    NationalityDatas = this.NationalityDatas,
                    NationalityId    = this.NationalityId,
                    UserId           = this.mainViewModel.UserData.UserId,
                };

                //  Delete the record
                response = await this.apiService.Post <CneIvssDataItem>(
                    MethodsHelper.GetUrlAPI(),
                    "/api",
                    "/CneIvssDatas/PostCneIvssDataByOption/?_option=cne",
                    this.mainViewModel.Token.TokenType,
                    this.mainViewModel.Token.AccessToken,
                    cneIvssDataItem);

                if (!response.IsSuccess)
                {
                    await this.dialogService.ShowMessage(
                        "Error",
                        response.Message,
                        "Accept");

                    return;
                }

                //  Delete record
                this.cantvViewModel.UpdateCneData(
                    -1,
                    ToCneItemViewModel(cneIvssDataItem));

                await dialogService.ShowMessage(
                    "Infromation",
                    string.Format(
                        "Record: {0} remove successfully...!!!",
                        cneIvssDataItem.GetCneIvssFull),
                    "Accept");
            }
        }
Exemplo n.º 21
0
        public async Task <IHttpActionResult> PutUser(int id, User _user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    //  return BadRequest(ModelState);
                    ModelState.AddModelError(string.Empty, "Error: User is not valid...!!!");
                    return(BadRequest("Error: User is not valid...!!!"));
                }

                if (id != _user.UserId)
                {
                    //  return BadRequest();
                    ModelState.AddModelError(string.Empty, "Error: Id is not equal to UserId...!!!");
                    return(BadRequest("Error: Id is not equal to UserId...!!!"));
                }

                db.Entry(_user).State = EntityState.Modified;
                response = await DbHelper.SaveChangeDB(db);

                if (!response.IsSuccess)
                {
                    ModelState.AddModelError(string.Empty, response.Message);
                    return(BadRequest(response.Message));
                }

                //  CHEJ - Sube las imagenes
                if (_user.ImageArray != null &&
                    _user.ImageArray.Length > 0)
                {
                    var stream = new MemoryStream(_user.ImageArray);
                    MethodsHelper.Image = _user.ImagePath;

                    //  CHEJ - Guarda la imagen en el FTP
                    MethodsHelper.Image =
                        FilesHelper.UploadPhoto(
                            stream,
                            MethodsHelper.GetPathUserImages(),
                            Convert.ToString(_user.UserId).Trim());

                    //  CHEJ - Da formato a la imagen
                    MethodsHelper.Image =
                        string.Format(
                            "{0}{1}",
                            MethodsHelper.GetPathUserImages(),
                            MethodsHelper.Image);

                    //  Actualiza la informacion del usuario
                    _user.ImagePath       = MethodsHelper.Image;
                    db.Entry(_user).State = EntityState.Modified;
                    response = await DbHelper.SaveChangeDB(db);

                    if (response.IsSuccess)
                    {
                        return(Ok(_user));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, response.Message);
                        return(BadRequest(response.Message));
                    }
                }
                //  return StatusCode(HttpStatusCode.NoContent);
                return(Ok(_user));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 22
0
        public async Task <IHttpActionResult> EditPassword(ServicesVzLaUserEdit _user)
        {
            //  var errorMessages = string.Empty;
            errorMessages = string.Empty;
            try
            {
                var email           = string.Empty;
                var currentPassword = string.Empty;
                var newPassword     = string.Empty;
                //  dynamic jsonObject = _user;

                if (!ModelState.IsValid)
                {
                    //  Gets error of the ModelState
                    errorMessages  = "Error: the UserEdit is not valid...!!!" + System.Char.ConvertFromUtf32(13);
                    errorMessages += MethodsHelper.GetErrorsModelState(ModelState);

                    ModelState.AddModelError(string.Empty, errorMessages);
                    return(BadRequest(errorMessages));
                }

                //  email = jsonObject.Email.Value;
                //  currentPassword = jsonObject.CurrentPassword.Value;
                //  newPassword = jsonObject.NewPassword.Value;
                email           = _user.Email;
                currentPassword = _user.Password;
                newPassword     = _user.NewPassword;


                var userContext = new ApplicationDbContext();
                var userManager =
                    new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(userContext));
                var userASP = userManager.FindByEmail(email);

                if (userASP == null)
                {
                    //  return NotFound();
                    ModelState.AddModelError(string.Empty, "Error: UserASP (By Email) is null...!!!");
                    return(BadRequest("Error: UserASP (By Email) is null...!!!"));
                }

                var response =
                    await userManager.ChangePasswordAsync(
                        userASP.Id,
                        currentPassword,
                        newPassword);

                if (!response.Succeeded)
                {
                    errorMessages  = "Error: " + System.Char.ConvertFromUtf32(13);
                    errorMessages += response.Errors.FirstOrDefault();
                    ModelState.AddModelError(string.Empty, errorMessages);
                    return(BadRequest(response.Errors.FirstOrDefault()));
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                errorMessages = string.Format("Error: {0}", ex.Message);
                //  return BadRequest("Incorrect call");
                return(BadRequest(errorMessages));
            }
        }
Exemplo n.º 23
0
        private async void Save()
        {
            var response = MethodsHelper.IsValidField(
                "I",
                8,
                20,
                "number tracking",
                this.Tracking,
                true,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "I",
                8,
                20,
                "number tracking",
                this.Tracking,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Define control format
            this.SetStatusControl(false, true, 1);

            response = await apiservices.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Define control format
                this.SetStatusControl(true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var zoomDataItem = new ZoomDataItem
            {
                Tracking   = this.Tracking,
                UserId     = mainViewModel.UserData.UserId,
                ZoomDataId = 0,
            };

            //  Save the data CatvData
            response = await apiservices.Post <ZoomDataItem>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/ZoomDatas",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                zoomDataItem);

            if (!response.IsSuccess)
            {
                //  Define control format
                SetStatusControl(true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Add new record
            cantvViewModel.LoadUserData();

            //  Define control format
            this.SetStatusControl(true, false, 0);

            //  Navigate to back
            await this.navigationService.GoBackOnMaster();
        }
Exemplo n.º 24
0
        private async void Register()
        {
            //  Validate the field of form
            var response = MethodsHelper.IsValidField(
                "S",
                3,
                20,
                "firts name",
                this.FirtsName,
                true,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                3,
                20,
                "last name",
                this.LastName,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email",
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                6,
                10,
                "password",
                this.Password,
                true,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                6,
                10,
                "password confirm",
                this.Confirm,
                true,
                true,
                this.Password);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, true, 1);

            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Use the user registration API
            var user = new User
            {
                AppName    = MethodsHelper.GetAppName(),
                Email      = this.Email,
                FirstName  = this.FirtsName,
                LastName   = this.LastName,
                Password   = this.Password,
                UserTypeId = Convert.ToInt32("5"),
            };

            response = await apiService.Post(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users",
                user);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, true, false, 0);

            //  Set Initialize the fields
            SetInitializaFields();

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                string.Format(
                    "{0}{1}",
                    "User registered successfully, you can now log in to the ",
                    "application whit this username and password...!!!"),
                "Accept");

            await navigationService.GoBackOnLogin();
        }
Exemplo n.º 25
0
        public static async Task NavigateToProfile(FacebookResponse profile)
        {
            if (profile == null)
            {
                mainViewModel.Login.SetStatusControl(true, true, false, 0);
                //await dialogService.ShowMessage(
                //"Error",
                //"the facebook response is not available, try later...!!!",
                //"Accept");
                navigationService.SetMainPage("LoginPage");
                //  Application.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }

            var token = await apiService.LoginFacebook(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users/LoginFacebook",
                profile);

            if (token == null)
            {
                mainViewModel.Login.SetStatusControl(true, true, false, 0);
                await dialogService.ShowMessage(
                    "Error",
                    "Login with facebook is not available, try later...!!!",
                    "Accept");

                //  Application.Current.MainPage = new NavigationPage(new LoginPage());
                navigationService.SetMainPage("LoginPage");
                return;
            }

            //  Get data of the user
            var response = await apiService.Get <UserDataResponse>(
                MethodsHelper.GetUrlAPI(),
                "/api/Users",
                "/GetServicesVzLaUSerByEmail",
                string.Format(
                    "/?email={0}",
                    token.UserName),
                token.TokenType,
                token.AccessToken);

            if (!response.IsSuccess)
            {
                mainViewModel.Login.SetStatusControl(true, true, false, 0);
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                navigationService.SetMainPage("LoginPage");
                return;
            }

            //  Load values of the UserData
            LoadOfValueUserData(
                (UserDataResponse)response.Result,
                mainViewModel);

            //  Load value to token
            mainViewModel.Token = token;

            //  Gets an instance of the CantvViewModel
            mainViewModel.Cantv = new CantvViewModel();

            //  Set the MainPage to MasterPage
            navigationService.SetMainPage("MasterPage");
        }
Exemplo n.º 26
0
        private async void Login()
        {
            //  Validate the fields of form
            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email",
                    "Accept");

                return;
            }

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "password",
                this.Password,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await this.dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Establece el estatus de los controles
            this.SetStatusControl(false, true, true, 1);

            //  Validate if there is an internet connection
            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Establece el estatus de los controles
                this.SetStatusControl(true, true, false, 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Get user Token
            var token = await this.apiService.GetToken(
                Email,
                Password,
                MethodsHelper.GetUrlAPI());

            if (token != null)
            {
                if (!string.IsNullOrEmpty(token.ErrorDescription))
                {
                    //  EStablishes the status of controls
                    this.SetStatusControl(true, true, false, 0);

                    await this.dialogService.ShowMessage(
                        "Error",
                        token.ErrorDescription,
                        "Accept");

                    return;
                }
            }
            else
            {
                //  Establishes the status of controls
                this.SetStatusControl(true, true, false, 0);

                await this.dialogService.ShowMessage(
                    "Error",
                    "An error has occurred, try later...!!!",
                    "Accept");

                return;
            }

            //  Get new instance of ViewModel (Token)
            this.mainViewModel.Token = token;

            //  Get new instance of MenuViewModel
            //  MainViewModel.GetInstance().Menu = new MenuViewModel();

            //  Establishes the status of controls
            this.SetInitialize();
            this.SetStatusControl(true, true, false, 0);

            //  Navigate to the page
            //  await navigationService.NavigateOnMaster("MenuPage");

            //  MainViewModel.GetInstance().Cantv = new CantvViewModel();
            this.mainViewModel.Cantv = new CantvViewModel();

            //  Define the MainPage
            this.navigationService.SetMainPage("MasterPage");
        }
        private async void Recovery()
        {
            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.Email,
                false,
                false,
                string.Empty);

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.Email);

            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid email...!!!",
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, "Green", 1);

            response = await apiService.PasswordRecovery(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users/PasswordRecovery",
                this.Email);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, false, "Green", 0);

            //  Set Initialize the fields
            LoadValuesControls(0);

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                "You new password has been successfully sent to email...!!!",
                "Accept");

            //  Navigate to LoginPage
            await navigationService.GoBackOnLogin();
        }
        private void LoadValuesControls(int _option, Zoom _zoom)
        {
            if (_option == 0)
            {
                this.TrackId       = string.Empty;
                this.Reference     = string.Empty;
                this.Status        = string.Empty;
                this.ShippinigType = string.Empty;
                this.Date          = string.Empty;
                this.Origin        = string.Empty;
                this.Destination   = string.Empty;
                this.MessageLabel  = string.Empty;
            }
            else
            {
                if (_zoom != null)
                {
                    if (!_zoom.Descripcion.Contains(
                            "la Cedula no esta registrada como asegurado"))
                    {
                        this.TrackId   = this.zoomItemViewModel.Tracking;
                        this.Reference = _zoom.Referencia;
                        this.Status    =
                            MethodsHelper.TitleText(_zoom.Estatus.Trim());
                        this.ShippinigType =
                            MethodsHelper.TitleText(_zoom.TipoEnvio.Trim());
                        this.Date   = _zoom.Fecha.Trim();
                        this.Origin =
                            MethodsHelper.TitleText(_zoom.Origen.Trim());
                        this.Destination = _zoom.Destino.Trim();

                        //if (_zoom.Seguimiento.Count > 0)
                        //{
                        //    Tracking =
                        //        new ObservableCollection<Seguimiento>(_zoom.Seguimiento);
                        //}
                        //else
                        //{
                        //    Tracking = new ObservableCollection<Seguimiento>();
                        //}
                        this.isValid = true;
                    }
                    else
                    {
                        this.MessageLabel = _zoom.Descripcion;
                        //  Sets status of controls
                        this.isValid = false;
                        this.SetStatusControl(true, false, "Red", -1);
                    }
                }
                else
                {
                    this.MessageLabel =
                        string.Format("{0}{1}{2}{3}",
                                      string.Format(
                                          "El número: {0} de rastreo no está ",
                                          this.zoomItemViewModel.Tracking),
                                      "registrado en el sistema o ha ingresado ",
                                      "un numero de rastreo erroneo, ",
                                      "favor verifique...!!!");
                    //  Sets status of controls
                    this.isValid = false;
                    this.SetStatusControl(true, false, "Red", -1);
                }
            }
        }
Exemplo n.º 29
0
        private async void Save()
        {
            //  Validate the field of form
            #region Current Email

            var response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email",
                this.CurrentEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            var isValidEmail = MethodsHelper.IsValidEmail(this.CurrentEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid current email",
                    "Accept");

                return;
            }

            #endregion Current Email

            // Verify if it is valid the email current
            if (!this.CurrentEmail.Equals(this.mainViewModel.UserData.Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "This email not are registered in the sistem...!!!",
                    "Accept");

                return;
            }

            #region New Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "new email",
                this.NewEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            isValidEmail = MethodsHelper.IsValidEmail(this.NewEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid new email",
                    "Accept");

                return;
            }

            #endregion New Email

            #region Confirm Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "confirm email",
                this.ConfirmEmail,
                false,
                false,
                string.Empty);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            isValidEmail = MethodsHelper.IsValidEmail(this.ConfirmEmail);
            if (!isValidEmail)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an valid confirm email",
                    "Accept");

                return;
            }

            #endregion Confirm Email

            #region Email Confirm and new Email

            response = MethodsHelper.IsValidField(
                "S",
                0,
                0,
                "email confirm",
                this.ConfirmEmail,
                false,
                true,
                this.NewEmail);
            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            #endregion Email Confirm and new Email

            //  Validate that the emails are different
            if (this.CurrentEmail.Equals(this.NewEmail))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new email can not be the same as the current email .. !!!",
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(false, true, "Green", 1);

            response = await apiService.CheckConnection();

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Use the user registration API
            var userEdit = new UserEdit
            {
                AppName    = MethodsHelper.GetAppName(),
                Email      = this.mainViewModel.UserData.Email,
                FirstName  = this.mainViewModel.UserData.FirstName,
                LastName   = this.mainViewModel.UserData.LastName,
                NewEmail   = this.newEmail,
                Password   = this.mainViewModel.UserData.Password,
                UserId     = this.mainViewModel.UserData.UserId,
                UserTypeId = 5,
            };

            response = await apiService.Put <UserEdit>(
                MethodsHelper.GetUrlAPI(),
                "/api",
                "/Users/PutUserEdit",
                "id",
                this.mainViewModel.Token.TokenType,
                this.mainViewModel.Token.AccessToken,
                userEdit);

            if (!response.IsSuccess)
            {
                //  Set status controls
                SetStatusControl(true, false, "Green", 0);

                await dialogService.ShowMessage(
                    "Error",
                    response.Message,
                    "Accept");

                return;
            }

            //  Set status controls
            SetStatusControl(true, false, "Green", 0);

            //  Set Initialize the fields
            LoadValuesControls(0);

            //  Go back login
            await dialogService.ShowMessage(
                "Information",
                "Successfully modified email, you must log in again...!!! ",
                "Accept");

            //  Navigate to LoginPage
            navigationService.SetMainPage("LoginPage");
        }
Exemplo n.º 30
0
        public async Task <IHttpActionResult> PostUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                try
                {
                    //  CHEJ - Crea el usuario en la App
                    db.Users.Add(user);
                    response = await DbHelper.SaveChangeDB(db);

                    if (!response.IsSuccess)
                    {
                        ModelState.AddModelError(string.Empty, response.Message);
                        return(BadRequest(ModelState));
                    }

                    //  CHEJ - Sube las imagenes
                    if (user.ImageArray != null &&
                        user.ImageArray.Length > 0)
                    {
                        var stream = new MemoryStream(user.ImageArray);
                        MethodsHelper.Image = user.ImagePath;

                        //  CHEJ - Guarda la imagen en el FTP
                        MethodsHelper.Image =
                            FilesHelper.UploadPhoto(
                                stream,
                                MethodsHelper.GetPathUserImages(),
                                Convert.ToString(user.UserId).Trim());

                        //  CHEJ - Da formato a la imagen
                        MethodsHelper.Image =
                            string.Format(
                                "{0}{1}",
                                MethodsHelper.GetPathUserImages(),
                                MethodsHelper.Image);

                        //  Actualiza la informacion del usuario
                        user.ImagePath       = MethodsHelper.Image;
                        db.Entry(user).State = EntityState.Modified;
                        response             = await DbHelper.SaveChangeDB(db);

                        if (response.IsSuccess)
                        {
                            return(Ok());
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, response.Message);
                            return(BadRequest(ModelState));
                        }
                    }

                    //  CHEJ - Crea el usuario ASP
                    UsersHelper.CreateUserASP(
                        user.Email,
                        WebConfigurationManager.AppSettings["RoleUser"].ToString().Trim(),
                        user.Password);

                    //  return CreatedAtRoute("DefaultApi", new { id = user.UserId }, user);
                    return(Ok());
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(BadRequest(ex.Message));
                }
            }
        }