示例#1
0
        public static async Task<bool> Modify(opt_guest_record entity)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (NayooDbEntities e = new NayooDbEntities())
                    {
                        var current = e.opt_guest_record.Where(x => x.recordId == entity.recordId &&
                                                                    x.recordUniqueId.Equals(entity.recordUniqueId)).FirstOrDefault();
                        if (current == null)
                            throw new Exception("Not found this object !");

                        entity.updatedDate = DateTime.Now;
                        e.Entry(entity).CurrentValues.SetValues(current);
                        var result = await e.SaveChangesAsync();
                        if (result <= 0)
                            throw new Exception("Record guest not complete !");

                        scope.Complete();
                        return true;
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw new Exception(ExceptionHelper.ExceptionMessage(ex));
            }
        }
示例#2
0
        public static async Task<opt_guest_record> Add(opt_guest_record entity)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (NayooDbEntities e = new NayooDbEntities())
                    {
                    A: string _guidId = Helper.NewUniqueId;

                        bool Ok = e.opt_guest_record.Any(x => x.recordUniqueId.Equals(_guidId));
                        if (Ok)
                            goto A;

                        entity.isActive = true;
                        entity.recordUniqueId = _guidId;
                        entity.createdDate = DateTime.Now;
                        entity.updatedDate = DateTime.Now;
                        entity.inDate = DateTime.Now; 
                        e.opt_guest_record.Add(entity);

                        var result = await e.SaveChangesAsync();
                        if (result <= 0)
                            throw new Exception("Record guest not complete !");

                        scope.Complete();
                        return entity;
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw new Exception(ExceptionHelper.ExceptionMessage(ex));
            }
        }