Esempio n. 1
0
        public override Expression CreateExpressionTree(ResolveContext ec)
        {
            if (left is NullLiteral)
            {
                ec.Report.Error(845, loc, "An expression tree cannot contain a coalescing operator with null left side");
            }

            UserCast   uc         = left as UserCast;
            Expression conversion = null;

            if (uc != null)
            {
                left = uc.Source;

                Arguments c_args = new Arguments(2);
                c_args.Add(new Argument(uc.CreateExpressionTree(ec)));
                c_args.Add(new Argument(left.CreateExpressionTree(ec)));
                conversion = CreateExpressionFactoryCall(ec, "Lambda", c_args);
            }

            Arguments args = new Arguments(3);

            args.Add(new Argument(left.CreateExpressionTree(ec)));
            args.Add(new Argument(right.CreateExpressionTree(ec)));
            if (conversion != null)
            {
                args.Add(new Argument(conversion));
            }

            return(CreateExpressionFactoryCall(ec, "Coalesce", args));
        }
Esempio n. 2
0
     //הרשמה
     public static WebResult <UserDTO> Register(UserDTO user)//האובייקט מגיע עם שדות חובה שכבר נבדקו
     {
         using (ProjectEntities db = new ProjectEntities())
         {
             User goodUser = UserCast.GetUser(user);
             if (db.Users.FirstOrDefault(w => w.passwordUser == goodUser.passwordUser) != null ||
                 db.Users.FirstOrDefault(w => w.mailUser == user.mailUser) != null)   // אם יש כבר כזו סיסמה או כזה מייל
             {
                 return new WebResult <UserDTO>
                        {
                            Message = "אחד מהנתונים שהוקשו קיימים במערכת",
                            Status  = false,
                            Value   = null
                        }
             }
             ;
             db.Users.Add(goodUser);
             db.SaveChanges();
             return(new WebResult <UserDTO>
             {
                 Message = "הנתונים נשמרו בהצלחה",
                 Value = user,
                 Status = true
             });
         }
     }
 }
Esempio n. 3
0
        //כניסה עם טוקן
        public static async Task <WebResult <LoginData <UserDTO> > > LoginToken(string email, string password, Uri requestUri)
        {
            var user = db.Users.Where(w => w.mailUser == email && w.passwordUser == password).FirstOrDefault();

            if (user != null)
            {
                UserDTO userDTO = UserCast.GetUserDTO(user);

                var accessToken = await GetTokenDataAsync(userDTO.mailUser, userDTO.passwordUser, requestUri);

                if (!string.IsNullOrEmpty(accessToken))
                {
                    return(new WebResult <LoginData <UserDTO> >
                    {
                        Status = true,
                        Message = "התחברת בהצלחה",
                        Value = new LoginData <UserDTO>
                        {
                            TokenJson = accessToken,
                            objectDTO = userDTO
                        }
                    });
                }
            }
            return(new WebResult <LoginData <UserDTO> >
            {
                Status = false,
                Message = " אין משתמש רשום בשם וסיסמא זו  ",
                Value = null
            });
        }
Esempio n. 4
0
        //ביטול משתמש
        //האם עושים מחיקה אמיתית??????????????????????
        public static WebResult <UserDTO> Delete(int code)
        {
            User user = db.Users.Find(code);

            if (user == null)
            {
                return new WebResult <UserDTO>
                       {
                           Message = "אחד מהנתונים שהוקשו שגויים",
                           Status  = false,
                           Value   = null
                       }
            }
            ;
            //הרי אסור לשנות את הרשימה forEach האם השורה הבאה נכונה, כי כשעושים ????????????????
            db.Searches.Where(s => s.codeUser == code).ToList().ForEach(f => db.Searches.Remove(f));
            db.Users.Remove(user);
            db.SaveChanges();
            return(new WebResult <UserDTO>
            {
                Message = "המחיקה בוצעה בהצלחה",
                Value = UserCast.GetUserDTO(user),
                Status = true
            });
        }
Esempio n. 5
0
        public static void ChangePassword(UserDTO userDTO)
        {
            User user = UserCast.CastToDAL(userDTO);

            db.Users.FirstOrDefault(u => u.userId == user.userId).userTz = userDTO.userTz;
            db.SaveChanges();
        }
Esempio n. 6
0
        public static List <UserDTO> GetStudents()
        {
            List <UserDTO> userDTOs = new List <UserDTO>();

            db.Users.ToList().ForEach(u => userDTOs.Add(UserCast.CastToDTO(u)));
            return(userDTOs.Where(w => w.entityTypeId == DTO.Type.student).ToList());
        }
Esempio n. 7
0
        public static UserDTO Login(UserDTO userDTO)
        {
            User user;

            if (userDTO.userName != null)
            {
                user = db.Users.FirstOrDefault(i => i.userTz == userDTO.userTz && i.userName == userDTO.userName);
            }
            else
            {
                user = db.Users.FirstOrDefault(i => i.userTz == userDTO.userTz);
            }

            if (user == null)
            {
                return(null);
            }
            return(UserCast.CastToDTO(user));
        }
Esempio n. 8
0
        //כניסה אם המשתמש רוצה לשנות את הפרטים שלו, לא קשור לחיפושים
        public static WebResult <UserDTO> Login(string email, string password)
        {
            User user = db.Users.FirstOrDefault(u => u.mailUser == email && u.passwordUser == password);

            if (user == null)
            {
                return new WebResult <UserDTO>
                       {
                           Message = "אחד מהנתונים שהוקשו שגויים",
                           Status  = false,
                           Value   = null
                       }
            }
            ;
            HttpContext.Current.Session["User"] = user;
            return(new WebResult <UserDTO>
            {
                Message = "הכניסה בוצעה בהצלחה",
                Value = UserCast.GetUserDTO(user),
                Status = true
            });
        }
Esempio n. 9
0
        //הרשמה עם טוקן
        public async static Task <WebResult <LoginData <UserDTO> > > RegisterToken(UserDTO userDTO, Uri request)
        {
            if (db.Users.FirstOrDefault(f => f.passwordUser == userDTO.passwordUser) != null ||
                db.Users.FirstOrDefault(f => f.mailUser == userDTO.mailUser) != null)
            {
                return new WebResult <LoginData <UserDTO> >()
                       {
                           Message = "אחד מהפרטים שהוקשו כבר קיים במערכת",
                           Status  = false,
                           Value   = null
                       }
            }
            ;
            db.Users.Add(UserCast.GetUser(userDTO));
            if (db.SaveChanges() > 0)
            {
                var accessToken = await GetTokenDataAsync(userDTO.mailUser, userDTO.passwordUser, request);

                if (!string.IsNullOrEmpty(accessToken))
                {
                    return(new WebResult <LoginData <UserDTO> >
                    {
                        Status = true,
                        Message = "התחברת בהצלחה",
                        Value = new LoginData <UserDTO>
                        {
                            TokenJson = accessToken,
                            objectDTO = userDTO
                        }
                    });
                }
            }
            return(new WebResult <LoginData <UserDTO> >()
            {
                Status = false,
                Message = "הרשמה נכשלה",
                Value = null
            });
        }
Esempio n. 10
0
        public static List <StudentWithSpecDTO> GetStudentsWithSpecs()
        {
            List <StudentWithSpecDTO> usersWithSpecs = new List <StudentWithSpecDTO>();

            db.Users.ToList().Where(u => UserCast.CastToDTO(u).entityTypeId == DTO.Type.student).ToList().ForEach(u2 =>
            {
                StudentWithSpecDTO studentWithSpec = new StudentWithSpecDTO()
                {
                    userId   = u2.userId,
                    userTz   = u2.userTz,
                    userName = u2.userName,
                    balance  = getBalanceByUser(UserCast.CastToDTO(u2)),
                    specs    = new List <SpecializationDTO>()
                };

                db.UserToSpecs.Where(us => us.userId == u2.userId).ToList().ForEach(us2 =>
                {
                    db.Specializations.Where(s => s.specId == us2.specId).ToList().ForEach(s2 => studentWithSpec.specs.Add(SpecializationCast.CastToDTO(s2)));
                });
                usersWithSpecs.Add(studentWithSpec);
            });
            return(usersWithSpecs);
        }
Esempio n. 11
0
		//
		// User-defined conversions
		//
		public static Expression UserDefinedConversion (ResolveContext rc, Expression source, TypeSpec target, UserConversionRestriction restr, Location loc)
		{
			List<MethodSpec> candidates = null;

			//
			// If S or T are nullable types, source_type and target_type are their underlying types
			// otherwise source_type and target_type are equal to S and T respectively.
			//
			TypeSpec source_type = source.Type;
			TypeSpec target_type = target;
			Expression source_type_expr;
			bool nullable_source = false;
			var implicitOnly = (restr & UserConversionRestriction.ImplicitOnly) != 0;

			if (source_type.IsNullableType) {
				// No unwrapping conversion S? -> T for non-reference types
				if (implicitOnly && !TypeSpec.IsReferenceType (target_type) && !target_type.IsNullableType) {
					source_type_expr = source;
				} else {
					source_type_expr = Nullable.Unwrap.CreateUnwrapped (source);
					source_type = source_type_expr.Type;
					nullable_source = true;
				}
			} else {
				source_type_expr = source;
			}

			if (target_type.IsNullableType)
				target_type = Nullable.NullableInfo.GetUnderlyingType (target_type);

			// Only these containers can contain a user defined implicit or explicit operators
			const MemberKind user_conversion_kinds = MemberKind.Class | MemberKind.Struct | MemberKind.TypeParameter;

			if ((source_type.Kind & user_conversion_kinds) != 0 && source_type.BuiltinType != BuiltinTypeSpec.Type.Decimal) {
				bool declared_only = source_type.IsStruct;

				var operators = MemberCache.GetUserOperator (source_type, Operator.OpType.Implicit, declared_only);
				if (operators != null) {
					FindApplicableUserDefinedConversionOperators (rc, operators, source_type_expr, target_type, restr, ref candidates);
				}

				if (!implicitOnly) {
					operators = MemberCache.GetUserOperator (source_type, Operator.OpType.Explicit, declared_only);
					if (operators != null) {
						FindApplicableUserDefinedConversionOperators (rc, operators, source_type_expr, target_type, restr, ref candidates);
					}
				}
			}

			if ((target.Kind & user_conversion_kinds) != 0 && target_type.BuiltinType != BuiltinTypeSpec.Type.Decimal) {
				bool declared_only = target.IsStruct || implicitOnly;

				var operators = MemberCache.GetUserOperator (target_type, Operator.OpType.Implicit, declared_only);
				if (operators != null) {
					FindApplicableUserDefinedConversionOperators (rc, operators, source_type_expr, target_type, restr, ref candidates);
				}

				if (!implicitOnly) {
					operators = MemberCache.GetUserOperator (target_type, Operator.OpType.Explicit, declared_only);
					if (operators != null) {
						FindApplicableUserDefinedConversionOperators (rc, operators, source_type_expr, target_type, restr, ref candidates);
					}
				}
			}

			if (candidates == null)
				return null;

			//
			// Find the most specific conversion operator
			//
			MethodSpec most_specific_operator;
			TypeSpec s_x, t_x;
			if (candidates.Count == 1) {
				most_specific_operator = candidates[0];
				s_x = most_specific_operator.Parameters.Types[0];
				t_x = most_specific_operator.ReturnType;
			} else {
				//
				// Pass original source type to find the best match against input type and
				// not the unwrapped expression
				//
				s_x = FindMostSpecificSource (rc, candidates, source.Type, source_type_expr, !implicitOnly);
				if (s_x == null)
					return null;

				t_x = FindMostSpecificTarget (candidates, target, !implicitOnly);
				if (t_x == null)
					return null;

				most_specific_operator = null;
				for (int i = 0; i < candidates.Count; ++i) {
					if (candidates[i].ReturnType == t_x && candidates[i].Parameters.Types[0] == s_x) {
						most_specific_operator = candidates[i];
						break;
					}
				}

				if (most_specific_operator == null) {
					//
					// Unless running in probing more
					//
					if ((restr & UserConversionRestriction.ProbingOnly) == 0) {
						MethodSpec ambig_arg = candidates [0];
						most_specific_operator = candidates [1];
						/*
						foreach (var candidate in candidates) {
							if (candidate.ReturnType == t_x)
								most_specific_operator = candidate;
							else if (candidate.Parameters.Types[0] == s_x)
								ambig_arg = candidate;
						}
						*/
						rc.Report.Error (457, loc,
							"Ambiguous user defined operators `{0}' and `{1}' when converting from `{2}' to `{3}'",
							ambig_arg.GetSignatureForError (), most_specific_operator.GetSignatureForError (),
							source.Type.GetSignatureForError (), target.GetSignatureForError ());
					}

					return ErrorExpression.Instance;
				}
			}

			//
			// Convert input type when it's different to best operator argument
			//
			if (s_x != source_type) {
				var c = source as Constant;
				if (c != null) {
					source = c.Reduce (rc, s_x);
					if (source == null)
						c = null;
				}

				if (c == null) {
					source = implicitOnly ?
						ImplicitConversionStandard (rc, source_type_expr, s_x, loc) :
						ExplicitConversionStandard (rc, source_type_expr, s_x, loc);
				}
			} else {
				source = source_type_expr;
			}

			source = new UserCast (most_specific_operator, source, loc).Resolve (rc);

			//
			// Convert result type when it's different to best operator return type
			//
			if (t_x != target_type) {
				//
				// User operator is of T?
				//
				if (t_x.IsNullableType && (target.IsNullableType || !implicitOnly)) {
					//
					// User operator return type does not match target type we need
					// yet another conversion. This should happen for promoted numeric
					// types only
					//
					if (t_x != target) {
						var unwrap = Nullable.Unwrap.CreateUnwrapped (source);

						source = implicitOnly ?
							ImplicitConversionStandard (rc, unwrap, target_type, loc) :
							ExplicitConversionStandard (rc, unwrap, target_type, loc);

						if (source == null)
							return null;

						if (target.IsNullableType)
							source = new Nullable.LiftedConversion (source, unwrap, target).Resolve (rc);
					}
				} else {
					source = implicitOnly ?
						ImplicitConversionStandard (rc, source, target_type, loc) :
						ExplicitConversionStandard (rc, source, target_type, loc);

					if (source == null)
						return null;
				}
			}


			//
			// Source expression is of nullable type and underlying conversion returns
			// only non-nullable type we need to lift it manually
			//
			if (nullable_source && !s_x.IsNullableType)
				return new Nullable.LiftedConversion (source, source_type_expr, target).Resolve (rc);

			//
			// Target is of nullable type but source type is not, wrap the result expression
			//
			if (target.IsNullableType && !t_x.IsNullableType)
				source = Nullable.Wrap.Create (source, target);

			return source;
		}
Esempio n. 12
0
 public static UserDTO GetTeacher()
 {
     return(UserCast.CastToDTO(db.Users.FirstOrDefault(u => u.entityTypeId == (int)DTO.Type.teacher)));
 }