示例#1
0
        public Guid AddPhotographer(string email, string pass, string photographerName, DateTime bDay, string userpic)
        {
            if (_usersDal.GetUserByEmail(email) != null)
            {
                throw new Exception("Already exists");
            }
            User user = new User();

            user.EMail = email;
            user.Pass  = pass;
            user.Role  = UserRoles.Photographer;
            user.ID    = Guid.NewGuid();


            _usersDal.AddUser(user);

            Photographer photographer = new Photographer(photographerName, bDay);

            photographer.ID     = photographer.ID = Guid.NewGuid();
            photographer.UserID = user.ID;
            photographer.Logo   = userpic;

            _photographersDal.AddPhotographer(photographer);
            return(photographer.ID);
        }
示例#2
0
        public ActionResult SaveEdit(Photographer photographer)
        {
            if (Session["USERNAME"] == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            SqlConnection connection = new SqlConnection(con);
            //Update AuthenticatedUser : FullName, PhoneNumber

            string     SQL     = "Update AuthenticatedUser set FullName=@name ,PhoneNumber=@phone where Email=@email";
            SqlCommand command = new SqlCommand(SQL, connection);

            command.Parameters.AddWithValue("@name", Request.Form["AuthenticatedUser.FullName"].Trim());
            command.Parameters.AddWithValue("@phone", Request.Form["AuthenticatedUser.phoneNumber"].Trim());
            command.Parameters.AddWithValue("@email", Session["USERNAME"].ToString());
            connection.Open();
            command.ExecuteNonQuery();
            //Update Photographer:isAvailable,Bio,LinkProject,LinkSocialMedia
            SQL     = "Update Photographer set isAvaiable=@isAvailable,Bio=@Bio,LinkSocialMedia=@link, LinkProject=@linkProject where Username=@Username";
            command = new SqlCommand(SQL, connection);

            command.Parameters.AddWithValue("@isAvailable", Request.Form["isReady"]);
            command.Parameters.AddWithValue("@Bio", Request.Form["Bio"].Trim());
            command.Parameters.AddWithValue("@link", Request.Form["LinkSocialMedia"].Trim());
            command.Parameters.AddWithValue("@linkProject", Request.Form["LinkProject"].Trim());
            command.Parameters.AddWithValue("@Username", Session["USERNAME"].ToString());

            command.ExecuteNonQuery();
            connection.Close();
            return(RedirectToAction("ViewProfile"));
        }
        public async Task <bool> Registration()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(ConfigurationSettings.AppSettings["userManagementBaseUri"]);
            var photographer = new Photographer()
            {
                FirstName             = this.FirstName,
                LastName              = this.LastName,
                UserName              = this.UserName,
                Email                 = this.Email,
                DateOfBirth           = this.DateOfBirth,
                PhoneNumber           = this.PhoneNumber,
                Password              = this.Password,
                Profession            = this.Profession,
                WorkExperience        = this.WorkExperience,
                HasGopro              = this.MoreInformation[0].IsSelected,
                HasCameraStabilizator = this.MoreInformation[1].IsSelected,
                HasDron               = this.MoreInformation[2].IsSelected,
                Camera                = new Camera()
                {
                    Model          = this.CameraModel,
                    IsProfessional = this.IsProfessional
                }
            };

            if (Male == true)
            {
                photographer.Gender = "Male";
            }
            else
            {
                photographer.Gender = "Female";
            }

            photographer.KnowledgeOfLanguages = "";
            foreach (var language in this.Languages)
            {
                if (language.IsSelected)
                {
                    photographer.KnowledgeOfLanguages += language.Text + ", ";
                }
            }


            var requestResult = await client.PostAsync("api/Photographer", new StringContent(JsonConvert.SerializeObject(photographer), Encoding.UTF8, "application/json"));

            var content = requestResult.Content;

            var jsonContent = content.ReadAsStringAsync().Result;

            var status = JsonConvert.DeserializeObject <Status>(jsonContent);

            if (!status.IsOk)
            {
                this.ErrorMessage = status.Message;
                return(false);
            }
            return(true);
        }
        public static void Display()
        {
            Photographer photographer = new Photographer();
            Phone        lumia950     = new Phone();

            photographer.TakePhoto(lumia950);
        }
示例#5
0
        private void lbPhotographers_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateEditingMode(EditingModes.Edit, ref emPhotographers, ref lblPhotographers, "Photographers");

            currentPhotographer = listPhotographers[lbPhotographers.SelectedIndex];
            LoadPhotographerData(currentPhotographer);
        }
示例#6
0
        static void Main(string[] args)
        {
            PhotoContext context = new PhotoContext();

            Photographer pesho = new Photographer()
            {
                Username     = "******",
                Password     = "******",
                RegisterDate = new System.DateTime(2017, 3, 12),
                BirthDate    = new System.DateTime(1997, 4, 1)
            };

            Photographer ivailo = new Photographer()
            {
                Username     = "******",
                Password     = "******",
                RegisterDate = new System.DateTime(2017, 3, 12),
                BirthDate    = new System.DateTime(1987, 5, 3)
            };

            Photographer mitko = new Photographer()
            {
                Username     = "******",
                Password     = "******",
                RegisterDate = new System.DateTime(2017, 3, 12),
                BirthDate    = new System.DateTime(1995, 9, 15)
            };

            context.Photographers.Add(mitko);
            context.Photographers.Add(ivailo);
            context.Photographers.Add(pesho);
            context.SaveChanges();
        }
示例#7
0
        public async Task <Photographer> CreateOne(Photographer photographer)
        {
            await _context.Photographer.AddAsync(photographer);

            _context.SaveChanges();
            return(photographer);
        }
示例#8
0
        public (string def, string index) PhotographerTest()
        {
            string def   = "";
            string index = "";
            Random rnd   = new Random();

            using (var context = new PhotoGalleryContext())
            {
                for (int i = 0; i < 5000; i++)
                {
                    var model = new Photographer();
                    model.Name   = "Test name" + i;
                    model.Age    = rnd.Next(600);
                    model.Status = "TestStatus_" + i;
                    context.Photographer.Add(model);
                }

                //default
                var startTime  = System.Diagnostics.Stopwatch.StartNew();
                var testResult = context.Photographer.FromSqlRaw("SELECT name, age, status FROM photographer");
                startTime.Stop();
                def = startTime.Elapsed.ToString();

                //index
                context.Photographer.FromSqlRaw("CREATE UNIQUE INDEX index_test ON photographer(name, age, status)");
                startTime = System.Diagnostics.Stopwatch.StartNew();
                var newResult = context.Photographer.FromSqlRaw("SELECT name, age, status FROM photographer");
                startTime.Stop();
                index = startTime.Elapsed.ToString();
            }
            return(def, index);
        }
        public static void Display()
        {
            Photographer ph = new Photographer();

            ph.TakePhoto(new Camera());
            ph.TakePhoto(new Phone());
        }
示例#10
0
        private async Task <Photographer> GetTripPhotographerAsync(int id)
        {
            var tokenClinet = new TokenClient(discovery.TokenEndpoint, "campingTrip", "secret");

            var tokenResponse = tokenClinet.RequestClientCredentialsAsync("userManagement").Result;

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri("http://localhost:5000/")
            };

            httpClient.SetBearerToken(tokenResponse.AccessToken);

            var photographer = new Photographer();

            var response = await httpClient.GetAsync("api/photographer/" + id);

            if (response.IsSuccessStatusCode)
            {
                var content = response.Content;

                var userJson = await content.ReadAsStringAsync();

                photographer = JsonConvert.DeserializeObject <Photographer>(userJson);
            }

            return(photographer);
        }
        private static void AddPhotographers(PhotoContext context)
        {
            var photographer1 = new Photographer()
            {
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            var photographer2 = new Photographer()
            {
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            var photographer3 = new Photographer()
            {
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            var photographer4 = new Photographer()
            {
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };

            context.Photographers.AddRange(new[] { photographer1, photographer2, photographer3, photographer4 });
            context.SaveChanges();
        }
		public static Photographer WithName(string name, NSManagedObjectContext context)
		{
			Photographer photographer = null;
			// This is just like Photo(Flickr)'s method.  Look there for commentary.
			if (name.Length > 0)
			{
				var request = new NSFetchRequest("Photographer")
				{
					SortDescriptors = new[] {new NSSortDescriptor("name", true, new Selector("localizedCaseInsensitiveCompare:"))},
					Predicate =  NSPredicate.FromFormat("name = %@", new NSObject[] {(NSString) name})
				};
				NSError error;
				var matches = context.ExecuteFetchRequest(request, out error);
				if (matches == null || matches.Length > 1)
				{
					// handle error
				}
				else if (matches.Length == 0)
				{
					photographer = InsertNewObject(context);
					photographer.Name = name;
				}
				else
				{
					photographer = (Photographer) matches.First();
				}
			}
			return photographer;
		}
        public IActionResult EditUserPassword([FromBody] UpdatedPassword photographer)
        {
            try
            {
                string email = photographer.email;

                Photographer dbUser = _database.GetPhotographerByEmail(email);
                if (dbUser != null)
                {
                    // Compare old password
                    if (_pwHelper.VerifyHashedPassword(dbUser.hashedPassword, photographer.oldPassword) == PasswordVerificationResult.Success)
                    {
                        string hash = _pwHelper.HashPassword(photographer.newPassword);
                        _database.UpdatePhotographerPassword(email, hash);

                        return(Ok(new { message = "Password updated" }));
                    }
                    else
                    {
                        return(Unauthorized(new { message = "Password provided is wrong" }));
                    }
                }
                else
                {
                    return(NotFound(new { message = "User email not found" }));
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                return(StatusCode(500));
            }
        }
        public IActionResult EditUser(string email, [FromBody] Photographer photographer)
        {
            try
            {
                Photographer user = _database.GetPhotographerByEmail(email);
                if (user != null)
                {
                    user.firstName       = photographer.firstName;
                    user.lastName        = photographer.lastName;
                    user.cellPhoneNumber = photographer.cellPhoneNumber;
                    user.address         = photographer.address;
                    user.company         = photographer.company;
                    user.orgNr           = photographer.orgNr;
                    user.city            = photographer.city;
                    user.postalCode      = photographer.postalCode;
                    user.postalCodeArea  = photographer.postalCodeArea;
                    user.available       = photographer.available;

                    _database.UpdatePhotographer(user);

                    IActionResult response = Ok(new { message = "Photographer was updated", user });
                    return(response);
                }
                else
                {
                    IActionResult response = NotFound(new { message = "User was not found by email" });
                    return(response);
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                return(StatusCode(500));
            }
        }
示例#15
0
        public async Task <Photographer> CreatePhotographer(Photographer p)
        {
            _ctx.Photographer.Add(p);
            await _ctx.SaveChangesAsync();

            return(p);
        }
示例#16
0
        // Photographer Generics
        Photographer SetupPhotographer()
        {
            Photographer item = new Photographer();

            item.Name = "RESTClient Test Photographer";
            return(item);
        }
示例#17
0
        public Photographer GetPhotographerById(Guid ID)
        {
            Photographer p     = new Photographer();
            string       query = "SELECT * from Photographer WHERE Id = " + "@id";

            if (connection.State == System.Data.ConnectionState.Closed)
            {
                if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }
            }

            SqlCommand cmd = getCommand(query);

            cmd.Parameters.AddWithValue("@id", ID);
            using (var reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    p.ID        = reader.GetGuid(0);
                    p.FirstName = reader.GetString(1);
                    p.LastName  = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                    {
                        p.Birthday = reader.GetDateTime(3);
                    }
                    if (!reader.IsDBNull(4))
                    {
                        p.Notes = reader.GetString(4);
                    }
                }
            }
            return(p);
        }
示例#18
0
        public static void ImportPhotographers()
        {
            IEnumerable <PhotographerDto> photographerDtos = ParseJson <PhotographerDto>(Constants.PhotographersPath);

            List <Photographer> photographers = new List <Photographer>();

            using (PhotographyWorkshopContext context = new PhotographyWorkshopContext())
            {
                foreach (PhotographerDto photographerDto in photographerDtos)
                {
                    if (photographerDto.FirstName == null || photographerDto.LastName == null)
                    {
                        Console.WriteLine(Messages.InvalidDate);
                        continue;
                    }

                    string phone = String.Empty;
                    if (photographerDto.Phone != null)
                    {
                        Regex regex = new Regex(@"\+\d{1,3}\/\d{8,10}");
                        if (regex.IsMatch(photographerDto.Phone))
                        {
                            phone = photographerDto.Phone;
                        }
                    }

                    Photographer photographerEntity = new Photographer()
                    {
                        FirstName = photographerDto.FirstName,
                        LastName  = photographerDto.LastName,
                        Phone     = phone
                    };

                    bool alreadyPassedPrimaryCamera = false;
                    photographerEntity.PrimaryCamera = GetRandomCamera(context, alreadyPassedPrimaryCamera);

                    alreadyPassedPrimaryCamera         = true;
                    photographerEntity.SecondaryCamera = GetRandomCamera(context, alreadyPassedPrimaryCamera);

                    foreach (var lensDtoId in photographerDto.Lenses)
                    {
                        Lens lensEntity = context.Lenses.FirstOrDefault(lens => lens.Id == lensDtoId);
                        if (lensEntity != null)
                        {
                            if (CheckLensCompatibility(photographerEntity, lensEntity))
                            {
                                photographerEntity.Lenses.Add(lensEntity);
                            }
                        }
                    }

                    Console.WriteLine($"Successfully imported {photographerEntity.FullName} | Lenses: {photographerEntity.Lenses.Count}");
                    photographers.Add(photographerEntity);
                }

                context.Photographers.AddRange(photographers);
                context.SaveChanges();
            }
        }
示例#19
0
 public void Insert(Photographer model)
 {
     using (var context = new PhotoGalleryContext())
     {
         context.Photographer.Add(model);
         context.SaveChanges();
     }
 }
        private static Photographer GetRandomOwner(PhotographyWorkshopContext context)
        {
            Random       rnd          = new Random();
            int          randomId     = rnd.Next(1, context.Photographers.Count() + 1);
            Photographer photographer = context.Photographers.Find(randomId);

            return(photographer);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Photographer photographer = db.Photographers.Find(id);

            db.Photographers.Remove(photographer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#22
0
        public IActionResult EditPho(Photographer p)
        {
            if (ModelState != null)
            {
                string wwwPath     = this.Environment.WebRootPath;
                string contentPath = this.Environment.ContentRootPath;

                string path = Path.Combine(this.Environment.WebRootPath, "Images");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                List <string> uploadedFiles = new List <string>();
                if (p.ImageFilePath != null)
                {
                    foreach (IFormFile postedFile in p.ImageFilePath)
                    {
                        string fileName = Path.GetFileName(postedFile.FileName);
                        using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                        {
                            postedFile.CopyTo(stream);
                            uploadedFiles.Add(fileName);
                            string       imgP   = "/Images/" + fileName;
                            Photographer edited = new Photographer();
                            edited                = context.Photographers.Where(po => po.Ph_Id == p.Ph_Id).FirstOrDefault();
                            edited.Ph_Name        = p.Ph_Name;
                            edited.Ph_PhoneNumber = p.Ph_PhoneNumber;
                            edited.Ph_Price       = p.Ph_Price;
                            edited.Ph_Address     = p.Ph_Address;
                            edited.Ph_CameraType  = p.Ph_CameraType;
                            edited.Ph_Offers      = p.Ph_Offers;
                            edited.Description    = p.Description;
                            edited.ImagePath      = imgP;
                            edited.TestDate       = p.TestDate;
                            context.SaveChanges();
                            return(RedirectToAction("TestPhoEdit", new { id = p.Ph_Id }));
                        }
                    }
                }
                else
                {
                    Photographer edited = new Photographer();
                    edited                = context.Photographers.Where(po => po.Ph_Id == p.Ph_Id).FirstOrDefault();
                    edited.Ph_Name        = p.Ph_Name;
                    edited.Ph_PhoneNumber = p.Ph_PhoneNumber;
                    edited.Ph_Price       = p.Ph_Price;
                    edited.Ph_Address     = p.Ph_Address;
                    edited.Ph_CameraType  = p.Ph_CameraType;
                    edited.Ph_Offers      = p.Ph_Offers;
                    edited.Description    = p.Description;
                    edited.ImagePath      = p.ImagePath;
                    edited.TestDate       = p.TestDate;
                    context.SaveChanges();
                    return(RedirectToAction("TestPhoEdit", new { id = p.Ph_Id }));
                }
            }
            return(View(p));
        }
示例#23
0
        //public IActionResult CreateAlbum()
        //{
        //    Photographer p = new Photographer();
        //    //p = context.Photographers.Where(p => p.Ph_Id == id).FirstOrDefault();
        //    context.Albums.ToList();
        //    context.Images.ToList();
        //    return View();
        //}
        public IActionResult CreateNewAlbum()
        {
            Photographer p = new Photographer();

            //p = context.Photographers.Where(p => p.Ph_Id == id).FirstOrDefault();
            context.Albums.ToList();
            context.Images.ToList();
            return(View());
        }
示例#24
0
        protected override void Seed(Photographers.Data.PhotographerContext context)
        {
            Photographer teo = new Photographer
            {
                Username     = "******",
                Password     = "******",
                Email        = "*****@*****.**",
                BirthDate    = DateTime.Now,
                RegisterDate = DateTime.Now.AddDays(-20)
            };

            context.Photographers
            .AddOrUpdate(p => p.Username, teo);
            context.SaveChanges();

            Picture demoPicture = new Picture()
            {
                Title          = "Demo",
                Caption        = "Demo",
                FileSystemPath = "/public/imags/demo.png"
            };

            context.Pictures.AddOrUpdate(i => i.Title, demoPicture);

            Album vitosha = new Album()
            {
                Name            = "Vitosha",
                BackgroundColor = "Blue",
                IsPublic        = true,
                //OwnerId = teo.Id
            };

            context.Albums.AddOrUpdate(a => a.Name, vitosha);
            vitosha.Pictures.Add(demoPicture);
            context.SaveChanges();

            PhotographerAlbum ph = new PhotographerAlbum()
            {
                Photographer_Id = teo.Id,
                Album_Id        = vitosha.Id,
                Role            = Role.Viewer
            };

            vitosha.Photographers.Add(ph);
            context.PhotographerAlbums.Add(ph);



            Tag mountainTag = new Tag()
            {
                Label = "mountain"
            };

            context.Tags.AddOrUpdate(t => t.Label, mountainTag);
            mountainTag.Albums.Add(vitosha);
            context.SaveChanges();
        }
示例#25
0
        public IActionResult PhoView(int id)
        {
            Photographer p = new Photographer();

            p = context.Photographers.Where(p => p.Ph_Id == id).FirstOrDefault();
            context.Albums.ToList();
            context.Images.ToList();
            return(View(p));
        }
        protected override void Seed(Photographers.Data.PhotoContext context)
        {
            Photographer dani = new Photographer()
            {
                Usename      = "Dani",
                Password     = "******",
                Email        = "*****@*****.**",
                BirthDate    = new DateTime(2005, 07, 20),
                RegisterDate = DateTime.Now
            };

            context.Photographers.AddOrUpdate(p => p.Usename, dani);
            context.SaveChanges();
            Picture demoPicture = new Picture()
            {
                Title    = "Demo",
                Caption  = "Demo",
                FilePath = "C:\\Temp"
            };

            context.Pictures.AddOrUpdate(p => p.Title, demoPicture);
            context.SaveChanges();

            Album RealMadrid = new Album()
            {
                Name            = "Real Madrid",
                BackgroundColor = "White",
                isPublic        = true,
            };

            context.Albums.AddOrUpdate(a => a.Name, RealMadrid);

            RealMadrid.Pictures.Add(demoPicture);
            context.SaveChanges();

            PhotographerAlbums ph = new PhotographerAlbums()
            {
                Photographer_Id = dani.Id,
                Album_Id        = RealMadrid.Id,
                Role            = Role.Owner
            };

            RealMadrid.Photographers.Add(ph);
            context.PhotographerAlbums.Add(ph);

            Tag realTag = new Tag()
            {
                Label = "#RM"
            };

            context.Tags.AddOrUpdate(t => t.Label, realTag);
            context.SaveChanges();
            realTag.Albums.Add(RealMadrid);
            RealMadrid.Tags.Add(realTag);

            context.SaveChanges();
        }
示例#27
0
        private static bool CheckLensCompatibility(Photographer photographer, Lens lens)
        {
            if (lens.CompatibleWith == photographer.PrimaryCamera.Make || lens.CompatibleWith == photographer.SecondaryCamera.Make)
            {
                return(true);
            }

            return(false);
        }
示例#28
0
        public void Update(Photographer entity)
        {
            var index = FakeDatabase.Photographers.FindIndex(p => p.Id == entity.Id);

            if (index > -1)
            {
                FakeDatabase.Photographers[index] = entity;
            }
        }
示例#29
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Photographer photographer = await db.Photographers.FindAsync(id);

            db.Photographers.Remove(photographer);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
示例#30
0
        public ActionResult ViewProfile()
        {
            string id = Session["USERNAME"].ToString();

            Photographer pho = db.Photographers.Find(id);

            pho.AuthenticatedUser = db.AuthenticatedUsers.Find(id);
            return(View(pho));
        }