Esempio n. 1
0
        public ResponseSuccess DELETE(int SkillId)
        {
            ResponseSuccess responseObject = new ResponseSuccess();

            try
            {
                using (var db = new LinkedinContext())
                {
                    var entity = db.Skills.Where(x => x.Id == SkillId).FirstOrDefault();
                    if (entity == null)
                    {
                        throw new Exception("skill_not_found");
                    }
                    db.Skills.Remove(entity);
                    db.SaveChanges();
                    responseObject.Success = true;
                }
            }
            catch (Exception ex)
            {
                responseObject.Success = false;
                responseObject.Details = ex.Message;
            }
            return(responseObject);
        }
Esempio n. 2
0
        public ResponseSuccess POST(Skill request, int userId)
        {
            ResponseSuccess responseObject = new ResponseSuccess();

            try
            {
                /* veri kontrolleri yapılacak */
                using (var db = new LinkedinContext())
                {
                    var user = db.Users.Where(x => x.Id == userId).Include(x => x.Skills).First();
                    request.UserId = userId;
                    if (request.Id == 0)
                    {
                        user.Skills.Add(request);
                    }
                    else
                    {
                        var oldEntity = user.Skills.Where(x => x.Id == request.Id).First();
                        oldEntity.Name = request.Name;
                    }
                    db.SaveChanges();
                    responseObject.Success = true;
                }
            }
            catch (Exception ex)
            {
                responseObject.Success = false;
                responseObject.Details = ex.Message;
            }
            return(responseObject);
        }
        public ResponseSuccess POST(Experience request, int UserID) // save and update işlemi
        {
            ResponseSuccess responseObject = new ResponseSuccess();

            try
            {
                using (var db = new LinkedinContext())
                {
                    if (string.IsNullOrEmpty(request.CompanyName))
                    {
                        throw new Exception("company_name_error");
                    }
                    if (request.StartingDate == null || request.StartingDate == DateTime.MinValue)
                    {
                        throw new Exception("starting_date_error");
                    }
                    /* diğer veri kontrolleri yapılacak */

                    var user = db.Users.Where(x => x.Id == UserID).Include(s => s.Experiencies).FirstOrDefault();
                    request.UserId = UserID;
                    if (request.Id == 0)
                    {
                        user.Experiencies.Add(request);
                    }
                    else
                    {
                        var oldEntity = user.Experiencies.Where(x => x.Id == request.Id).FirstOrDefault();
                        oldEntity.CompanyName  = request.CompanyName;
                        oldEntity.StartingDate = request.StartingDate;
                        oldEntity.EndDate      = request.EndDate;
                        oldEntity.Location     = request.Location;
                        oldEntity.Position     = request.Position;
                        oldEntity.Description  = request.Description;
                    }
                    db.SaveChanges();
                    responseObject.Success = true;
                }
            }
            catch (Exception ex)
            {
                responseObject.Success = false;
                responseObject.Details = ex.Message;
            }
            return(responseObject);
        }
Esempio n. 4
0
        public ResponseSuccess POST(User request) // UPDATE ve Create işlemi burada.
        {
            ResponseSuccess responseObject = new ResponseSuccess()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(request.Name))
                {
                    throw new Exception("name_is_empty");
                }
                if (request == null)
                {
                    throw new Exception("request_is_empty");
                }
                /* diğer veri kontrolleri yapılacak */
                using (var db = new LinkedinContext())
                {
                    if (request.Id == 0)
                    {
                        // id null geldi yeni kullanıcı ekleyeceğiz demektir.
                        db.Users.Add(request);
                    }
                    else
                    {
                        db.Users.Update(request);
                    }
                    db.SaveChanges();
                    responseObject.Success = true;
                }
            }
            catch (Exception ex)
            {
                responseObject.Success = false;
                responseObject.Details = ex.Message;
            }

            return(responseObject);
        }
Esempio n. 5
0
        public ResponseSuccess DELETE(int UserId)
        {
            ResponseSuccess responseObject = new ResponseSuccess();

            using (var db = new LinkedinContext())
            {
                var user = db.Users.Where(x => x.Id == UserId).FirstOrDefault();
                if (user != null)
                {
                    db.Users.Remove(user);
                    db.SaveChanges();
                    responseObject.Success = true;
                }
                else
                {
                    responseObject.Success = false;
                    responseObject.Details = "user_not_found";
                }
            }
            return(responseObject);
        }