Ejemplo n.º 1
0
        public async Task <dynamic> Update(Userdetail user)
        {
            if (dbContext.Userdetails.Where(x => x.Username == user.Username && x.Userdetailid != user.Userdetailid).Any())
            {
                throw new Exception(string.Format(ValidationMessages.DUPLICATE, PropertyNames.USER));
            }

            //var objUser = dbContext.Users.Where(x => x.Userid == user.Userid).FirstOrDefault();
            if (dbContext.Userdetails.Where(x => x.Userdetailid == user.Userdetailid && x.Lastmodifieddate == user.Lastmodifieddate).Any())
            {
                user.Lastmodifieddate       = DateTime.UtcNow;
                dbContext.Entry(user).State = EntityState.Modified;
                dbContext.SaveChanges();
                return(await System.Threading.Tasks.Task.FromResult(user));
            }
            else
            {
                throw new Exception(string.Format(ValidationMessages.DELETEDORUPDATED, PropertyNames.USER));
            }
        }
Ejemplo n.º 2
0
        public async Task <Article> Update(Article article)
        {
            //var objUser = dbContext.Users.Where(x => x.Userid == user.Userid).FirstOrDefault();
            if (_dbContext.Articles.Where(x => x.Articleid == article.Articleid && x.Isdeleted == false).Any())
            {
                if (article.Submittedtoid != null || article.Submitteddate != null)
                {
                    throw new Exception(string.Format(ValidationMessages.ARTICLEALREADYSUBMITTED));
                }
                article.Lastmodifieddate = DateTime.UtcNow;

                _dbContext.Entry(article).State = EntityState.Modified;
                _dbContext.SaveChanges();



                article.Tags.ToList().ForEach(x =>
                {
                    x.Lastmodifieddate = DateTime.UtcNow;
                    if (x.Tagid != 0)
                    {
                        _dbContext.Entry(x).State = EntityState.Modified;
                    }
                    else
                    {
                        x.Articleid = article.Articleid;
                        _dbContext.Tags.Add(x);
                    }
                });

                _dbContext.SaveChanges();

                return(await System.Threading.Tasks.Task.FromResult(article));
            }
            else
            {
                throw new Exception(string.Format(ValidationMessages.DELETEDORUPDATED, PropertyNames.ARTICLE));
            }
        }