Example #1
0
        public async Task <ActionResult> Add([FromBody] ShishaDTO shisha)
        {
            var currentUser = await this.usersService.GetCurrentUser();

            var result = new MongoModels.Shisha();

            if (this.IsCurrentUserAdmin(currentUser) && shisha.IsPublic)
            {
                result = await this.shishasService.Add(Mapper.ToEntity(shisha));
            }
            else
            {
                result = await this.shishasService.AddToWishList(Mapper.ToEntity(shisha));
            }

            return(Created($"{Request.Path}/{result.Id}", result.ToDto()));
        }
Example #2
0
 public static Shisha ToEntity(this ShishaDTO shisha) => new Shisha
 {
     Id             = shisha.Id,
     Identifier     = shisha.Identifier,
     Name           = shisha.Name,
     Description    = shisha.Description,
     Type           = shisha.Type,
     Tag            = shisha.Tag,
     Picture        = shisha.Picture,
     Power          = shisha.Power,
     IsPublic       = shisha.IsPublic,
     IsFavourite    = shisha.IsFavourite,
     IsWish         = shisha.IsWish,
     IsSeasonal     = shisha.IsSeasonal,
     Tabaccos       = Mapper.ToEntity(shisha.Tabaccos).ToArray(),
     OwnRating      = shisha.OwnRating,
     TotalRating    = shisha.TotalRating,
     CreatedAt      = shisha.CreatedAt != null ? (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(shisha.CreatedAt)) : new DateTime(),
     CreatedBy      = shisha.CreatedBy,
     LastModifiedAt = shisha.LastModifiedAt != null ? (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(shisha.LastModifiedAt)) : new DateTime(),
     LastModifiedBy = shisha.LastModifiedBy
 };